This source file includes following definitions.
- REMAINDER
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #if ! (defined USE_LONG_DOUBLE || defined USE_FLOAT)
18 # include <config.h>
19 #endif
20
21
22 #include <math.h>
23
24 #ifdef USE_LONG_DOUBLE
25 # define REMAINDER remainderl
26 # define DOUBLE long double
27 # define L_(literal) literal##L
28 # define FABS fabsl
29 # define FMOD fmodl
30 # define ISNAN isnanl
31 #elif ! defined USE_FLOAT
32 # define REMAINDER remainder
33 # define DOUBLE double
34 # define L_(literal) literal
35 # define FABS fabs
36 # define FMOD fmod
37 # define ISNAN isnand
38 #else
39 # define REMAINDER remainderf
40 # define DOUBLE float
41 # define L_(literal) literal##f
42 # define FABS fabsf
43 # define FMOD fmodf
44 # define ISNAN isnanf
45 #endif
46
47 #undef NAN
48 #if defined _MSC_VER
49 static DOUBLE zero;
50 # define NAN (zero / zero)
51 #else
52 # define NAN (L_(0.0) / L_(0.0))
53 #endif
54
55 DOUBLE
56 REMAINDER (DOUBLE x, DOUBLE y)
57 {
58 if (isfinite (x) && isfinite (y) && y != L_(0.0))
59 {
60 if (x == L_(0.0))
61
62 return x;
63
64 {
65 int negate = ((!signbit (x)) ^ (!signbit (y)));
66 DOUBLE r;
67
68
69 x = FABS (x);
70 y = FABS (y);
71
72
73 if (x <= L_(0.5) * y)
74 return (negate ? - x : x);
75
76
77
78
79 x = FMOD (x, L_(2.0) * y);
80
81
82
83
84
85 if (x <= L_(0.5) * y)
86 r = x;
87 else
88 {
89 r = x - y;
90 if (r > L_(0.5) * y)
91 r = x - L_(2.0) * y;
92 }
93 return (negate ? - r : r);
94 }
95 }
96 else
97 {
98 if (ISNAN (x) || ISNAN (y))
99 return x + y;
100 else if (isinf (y))
101 return x;
102 else
103
104 return NAN;
105 }
106 }