Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * ====================================================
  3.  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4.  *
  5.  * Developed at SunPro, a Sun Microsystems, Inc. business.
  6.  * Permission to use, copy, modify, and distribute this
  7.  * software is freely granted, provided that this notice
  8.  * is preserved.
  9.  * ====================================================
  10.  */
  11.  
  12. #include "fdlibm.h"
  13.  
  14. #ifdef __STDC__
  15.         float truncf(float x)
  16. #else
  17.         float truncf(x)
  18.         float x;
  19. #endif
  20. {
  21.   __int32_t signbit, w, exponent_less_127;
  22.  
  23.   GET_FLOAT_WORD(w,x);
  24.  
  25.   /* Extract sign bit. */
  26.   signbit = w & 0x80000000;
  27.  
  28.   /* Extract exponent field. */
  29.   exponent_less_127 = ((w & 0x7f800000) >> 23) - 127;
  30.  
  31.   if (exponent_less_127 < 23)
  32.     {
  33.       if (exponent_less_127 < 0)
  34.         {
  35.           /* -1 < x < 1, so result is +0 or -0. */
  36.           SET_FLOAT_WORD(x, signbit);
  37.         }
  38.       else
  39.         {
  40.           SET_FLOAT_WORD(x, signbit | (w & ~(0x007fffff >> exponent_less_127)));
  41.         }
  42.     }
  43.   else
  44.     {
  45.       if (exponent_less_127 == 255)
  46.         /* x is NaN or infinite. */
  47.         return x + x;
  48.  
  49.       /* All bits in the fraction field are relevant. */
  50.     }
  51.   return x;
  52. }
  53.  
  54. #ifdef _DOUBLE_IS_32BITS
  55.  
  56. #ifdef __STDC__
  57.         double trunc(double x)
  58. #else
  59.         double trunc(x)
  60.         double x;
  61. #endif
  62. {
  63.         return (double) truncf((float) x);
  64. }
  65.  
  66. #endif /* defined(_DOUBLE_IS_32BITS) */
  67.