8 #if (__BYTE_ORDER == __BIG_ENDIAN)
19 static const unsigned long int signMask = 0x80000000ul;
20 static const double twoTo52 = 4503599627370496.0;
22 /*******************************************************************************
24 * The function round rounds its double argument to integral value *
25 * according to the "add half to the magnitude and truncate" rounding of *
26 * Pascal's Round function and FORTRAN's ANINT function and returns the *
27 * result in double format. This function signals inexact if an ordered *
28 * return value is not equal to the operand. *
30 *******************************************************************************/
32 libm_hidden_proto(round)
33 double round ( double x )
35 DblInHex argument, OldEnvironment;
37 register unsigned long int xHead;
38 register long int target;
41 xHead = argument.words.hi & 0x7fffffffUL; // xHead <- high half of |x|
42 target = ( argument.words.hi < signMask ); // flag positive sign
44 if ( xHead < 0x43300000ul )
45 /*******************************************************************************
47 *******************************************************************************/
49 if ( xHead < 0x3ff00000ul )
50 /*******************************************************************************
52 *******************************************************************************/
54 asm ("mffs %0" : "=f" (OldEnvironment.dbl)); // get environment
55 if ( xHead < 0x3fe00000ul )
56 /*******************************************************************************
58 *******************************************************************************/
60 if ( ( xHead | argument.words.lo ) != 0ul )
61 OldEnvironment.words.lo |= 0x02000000ul;
62 asm ("mtfsf 255,%0" : /*NULLOUT*/ : /*IN*/ "f" ( OldEnvironment.dbl ));
68 /*******************************************************************************
69 * Is 0.5 ² |x| < 1.0? *
70 *******************************************************************************/
71 OldEnvironment.words.lo |= 0x02000000ul;
72 asm ("mtfsf 255,%0" : /*NULLOUT*/ : /*IN*/ "f" ( OldEnvironment.dbl ));
78 /*******************************************************************************
79 * Is 1.0 < |x| < 2.0^52? *
80 *******************************************************************************/
83 y = ( x + twoTo52 ) - twoTo52; // round at binary point
84 if ( y == x ) // exact case
86 z = x + 0.5; // inexact case
87 y = ( z + twoTo52 ) - twoTo52; // round at binary point
94 /*******************************************************************************
96 *******************************************************************************/
99 y = ( x - twoTo52 ) + twoTo52; // round at binary point
103 y = ( z - twoTo52 ) + twoTo52; // round at binary point
110 /*******************************************************************************
111 * |x| >= 2.0^52 or x is a NaN. *
112 *******************************************************************************/
115 libm_hidden_def(round)