4 /*******************************************************************************
6 * The function nearbyint rounds its double argument to integral value *
7 * according to the current rounding direction and returns the result in *
8 * double format. This function does not signal inexact. *
10 ********************************************************************************
12 * This function calls fabs and copysign. *
14 *******************************************************************************/
16 static const double twoTo52 = 4503599627370496.0;
18 libm_hidden_proto(nearbyint)
19 double nearbyint ( double x )
22 double OldEnvironment;
26 __asm__ ("mffs %0" : "=f" (OldEnvironment)); /* get the environement */
28 if ( fabs ( x ) >= y ) /* huge case is exact */
30 if ( x < 0 ) y = -y; /* negative case */
31 y = ( x + y ) - y; /* force rounding */
32 if ( y == 0.0 ) /* zero results mirror sign of x */
33 y = copysign ( y, x );
35 __asm__ ("mtfsf 255,%0" : /*NULLOUT*/ : /*IN*/ "f" ( OldEnvironment ));
38 libm_hidden_def(nearbyint)