1 | |
---|
2 | /* @(#)w_fmod.c 5.1 93/09/24 */ |
---|
3 | /* |
---|
4 | * ==================================================== |
---|
5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
---|
6 | * |
---|
7 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
---|
8 | * Permission to use, copy, modify, and distribute this |
---|
9 | * software is freely granted, provided that this notice |
---|
10 | * is preserved. |
---|
11 | * ==================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | /* |
---|
15 | FUNCTION |
---|
16 | <<fmod>>, <<fmodf>>---floating-point remainder (modulo) |
---|
17 | |
---|
18 | INDEX |
---|
19 | fmod |
---|
20 | INDEX |
---|
21 | fmodf |
---|
22 | |
---|
23 | SYNOPSIS |
---|
24 | #include <math.h> |
---|
25 | double fmod(double <[x]>, double <[y]>); |
---|
26 | float fmodf(float <[x]>, float <[y]>); |
---|
27 | |
---|
28 | DESCRIPTION |
---|
29 | The <<fmod>> and <<fmodf>> functions compute the floating-point |
---|
30 | remainder of <[x]>/<[y]> (<[x]> modulo <[y]>). |
---|
31 | |
---|
32 | RETURNS |
---|
33 | The <<fmod>> function returns the value |
---|
34 | @ifnottex |
---|
35 | <[x]>-<[i]>*<[y]>, |
---|
36 | @end ifnottex |
---|
37 | @tex |
---|
38 | $x-i\times y$, |
---|
39 | @end tex |
---|
40 | for the largest integer <[i]> such that, if <[y]> is nonzero, the |
---|
41 | result has the same sign as <[x]> and magnitude less than the |
---|
42 | magnitude of <[y]>. |
---|
43 | |
---|
44 | <<fmod(<[x]>,0)>> returns NaN, and sets <<errno>> to <<EDOM>>. |
---|
45 | |
---|
46 | You can modify error treatment for these functions using <<matherr>>. |
---|
47 | |
---|
48 | PORTABILITY |
---|
49 | <<fmod>> is ANSI C. <<fmodf>> is an extension. |
---|
50 | */ |
---|
51 | |
---|
52 | /* |
---|
53 | * wrapper fmod(x,y) |
---|
54 | */ |
---|
55 | |
---|
56 | #include "fdlibm.h" |
---|
57 | #include <errno.h> |
---|
58 | |
---|
59 | #ifndef _DOUBLE_IS_32BITS |
---|
60 | |
---|
61 | #ifdef __STDC__ |
---|
62 | double fmod(double x, double y) /* wrapper fmod */ |
---|
63 | #else |
---|
64 | double fmod(x,y) /* wrapper fmod */ |
---|
65 | double x,y; |
---|
66 | #endif |
---|
67 | { |
---|
68 | #ifdef _IEEE_LIBM |
---|
69 | return __ieee754_fmod(x,y); |
---|
70 | #else |
---|
71 | double z; |
---|
72 | struct exception exc; |
---|
73 | z = __ieee754_fmod(x,y); |
---|
74 | if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z; |
---|
75 | if(y==0.0) { |
---|
76 | /* fmod(x,0) */ |
---|
77 | exc.type = DOMAIN; |
---|
78 | exc.name = "fmod"; |
---|
79 | exc.arg1 = x; |
---|
80 | exc.arg2 = y; |
---|
81 | exc.err = 0; |
---|
82 | if (_LIB_VERSION == _SVID_) |
---|
83 | exc.retval = x; |
---|
84 | else |
---|
85 | exc.retval = 0.0/0.0; |
---|
86 | if (_LIB_VERSION == _POSIX_) |
---|
87 | errno = EDOM; |
---|
88 | else if (!matherr(&exc)) { |
---|
89 | errno = EDOM; |
---|
90 | } |
---|
91 | if (exc.err != 0) |
---|
92 | errno = exc.err; |
---|
93 | return exc.retval; |
---|
94 | } else |
---|
95 | return z; |
---|
96 | #endif |
---|
97 | } |
---|
98 | |
---|
99 | #endif /* defined(_DOUBLE_IS_32BITS) */ |
---|