summaryrefslogtreecommitdiff
path: root/libm/powerpc/classic/s_nearbyint.c
diff options
context:
space:
mode:
authorJoakim Tjernlund <joakim.tjernlund@transmode.se>2007-03-31 13:28:15 +0000
committerJoakim Tjernlund <joakim.tjernlund@transmode.se>2007-03-31 13:28:15 +0000
commite7bcf43b6440ac9fc61a0eef5591393810daafb5 (patch)
treeb72c3fb15e030b47b2eb02d13169b4548382e855 /libm/powerpc/classic/s_nearbyint.c
parent7a40ba19c86e4d2fc7e35f14a0e629ee843b96a9 (diff)
From Steve Papacharalambous:
Add math support for PowerPC e500.
Diffstat (limited to 'libm/powerpc/classic/s_nearbyint.c')
-rw-r--r--libm/powerpc/classic/s_nearbyint.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/libm/powerpc/classic/s_nearbyint.c b/libm/powerpc/classic/s_nearbyint.c
new file mode 100644
index 000000000..068e21378
--- /dev/null
+++ b/libm/powerpc/classic/s_nearbyint.c
@@ -0,0 +1,38 @@
+#include <limits.h>
+#include <math.h>
+
+/*******************************************************************************
+* *
+* The function nearbyint rounds its double argument to integral value *
+* according to the current rounding direction and returns the result in *
+* double format. This function does not signal inexact. *
+* *
+********************************************************************************
+* *
+* This function calls fabs and copysign. *
+* *
+*******************************************************************************/
+
+static const double twoTo52 = 4503599627370496.0;
+
+libm_hidden_proto(nearbyint)
+double nearbyint ( double x )
+ {
+ double y;
+ double OldEnvironment;
+
+ y = twoTo52;
+
+ asm ("mffs %0" : "=f" (OldEnvironment)); /* get the environement */
+
+ if ( fabs ( x ) >= y ) /* huge case is exact */
+ return x;
+ if ( x < 0 ) y = -y; /* negative case */
+ y = ( x + y ) - y; /* force rounding */
+ if ( y == 0.0 ) /* zero results mirror sign of x */
+ y = copysign ( y, x );
+// restore old flags
+ asm ("mtfsf 255,%0" : /*NULLOUT*/ : /*IN*/ "f" ( OldEnvironment ));
+ return ( y );
+ }
+libm_hidden_def(nearbyint)