move benchmarks to their own dir.
[minix.git] / lib / i386 / math / arch_round.c
bloba239f3636d21d04ec7f444bb7bd3222f68500610
1 #include <errno.h>
2 #include <fenv.h>
3 #include <math.h>
5 #include "fpu_cw.h"
6 #include "fpu_round.h"
8 static double rndint(double x, u16_t cw_bits, u16_t cw_mask)
10 u16_t cw;
12 /* set FPUCW to the right value */
13 cw = fpu_cw_get();
14 fpu_cw_set((cw & cw_mask) | cw_bits);
16 /* perform the round */
17 fpu_rndint(&x);
19 /* restore FPUCW */
20 fpu_cw_set(cw);
21 return x;
24 double nearbyint(double x)
26 /* round, disabling floating point precision error */
27 return rndint(x, FPUCW_EXCEPTION_MASK_PM, ~0);
30 double remainder(double x, double y)
32 int xclass, yclass;
34 /* check arguments */
35 xclass = fpclassify(x);
36 yclass = fpclassify(y);
37 if (xclass == FP_NAN || yclass == FP_NAN)
38 return NAN;
40 if (xclass == FP_INFINITE || yclass == FP_ZERO)
42 errno = EDOM;
43 return NAN;
46 /* call the assembly implementation */
47 fpu_remainder(&x, y);
48 return x;
51 double trunc(double x)
53 /* round in truncate mode, disabling floating point precision error */
54 return rndint(x,
55 FPUCW_EXCEPTION_MASK_PM | FPUCW_ROUNDING_CONTROL_TRUNC,
56 ~FPUCW_ROUNDING_CONTROL);