src/libm/s_floor.c
changeset 3337 9ac6f0782dd6
parent 3162 dc1eb82ffdaa
child 6044 35448a5ea044
equal deleted inserted replaced
3336:00fab0ebfe54 3337:9ac6f0782dd6
    26 
    26 
    27 #include "math.h"
    27 #include "math.h"
    28 #include "math_private.h"
    28 #include "math_private.h"
    29 
    29 
    30 #ifdef __STDC__
    30 #ifdef __STDC__
    31 static const double huge = 1.0e300;
    31 static const double huge_val = 1.0e300;
    32 #else
    32 #else
    33 static double huge = 1.0e300;
    33 static double huge_val = 1.0e300;
    34 #endif
    34 #endif
    35 
    35 
    36 libm_hidden_proto(floor)
    36 libm_hidden_proto(floor)
    37 #ifdef __STDC__
    37 #ifdef __STDC__
    38      double floor(double x)
    38      double floor(double x)
    45     u_int32_t i, j;
    45     u_int32_t i, j;
    46     EXTRACT_WORDS(i0, i1, x);
    46     EXTRACT_WORDS(i0, i1, x);
    47     j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
    47     j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
    48     if (j0 < 20) {
    48     if (j0 < 20) {
    49         if (j0 < 0) {           /* raise inexact if x != 0 */
    49         if (j0 < 0) {           /* raise inexact if x != 0 */
    50             if (huge + x > 0.0) {       /* return 0*sign(x) if |x|<1 */
    50             if (huge_val + x > 0.0) {       /* return 0*sign(x) if |x|<1 */
    51                 if (i0 >= 0) {
    51                 if (i0 >= 0) {
    52                     i0 = i1 = 0;
    52                     i0 = i1 = 0;
    53                 } else if (((i0 & 0x7fffffff) | i1) != 0) {
    53                 } else if (((i0 & 0x7fffffff) | i1) != 0) {
    54                     i0 = 0xbff00000;
    54                     i0 = 0xbff00000;
    55                     i1 = 0;
    55                     i1 = 0;
    57             }
    57             }
    58         } else {
    58         } else {
    59             i = (0x000fffff) >> j0;
    59             i = (0x000fffff) >> j0;
    60             if (((i0 & i) | i1) == 0)
    60             if (((i0 & i) | i1) == 0)
    61                 return x;       /* x is integral */
    61                 return x;       /* x is integral */
    62             if (huge + x > 0.0) {       /* raise inexact flag */
    62             if (huge_val + x > 0.0) {       /* raise inexact flag */
    63                 if (i0 < 0)
    63                 if (i0 < 0)
    64                     i0 += (0x00100000) >> j0;
    64                     i0 += (0x00100000) >> j0;
    65                 i0 &= (~i);
    65                 i0 &= (~i);
    66                 i1 = 0;
    66                 i1 = 0;
    67             }
    67             }
    73             return x;           /* x is integral */
    73             return x;           /* x is integral */
    74     } else {
    74     } else {
    75         i = ((u_int32_t) (0xffffffff)) >> (j0 - 20);
    75         i = ((u_int32_t) (0xffffffff)) >> (j0 - 20);
    76         if ((i1 & i) == 0)
    76         if ((i1 & i) == 0)
    77             return x;           /* x is integral */
    77             return x;           /* x is integral */
    78         if (huge + x > 0.0) {   /* raise inexact flag */
    78         if (huge_val + x > 0.0) {   /* raise inexact flag */
    79             if (i0 < 0) {
    79             if (i0 < 0) {
    80                 if (j0 == 20)
    80                 if (j0 == 20)
    81                     i0 += 1;
    81                     i0 += 1;
    82                 else {
    82                 else {
    83                     j = i1 + (1 << (52 - j0));
    83                     j = i1 + (1 << (52 - j0));