1 | |
---|
2 | /* @(#)w_remainder.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 | <<remainder>>, <<remainderf>>---round and remainder |
---|
17 | INDEX |
---|
18 | remainder |
---|
19 | INDEX |
---|
20 | remainderf |
---|
21 | |
---|
22 | SYNOPSIS |
---|
23 | #include <math.h> |
---|
24 | double remainder(double <[x]>, double <[y]>); |
---|
25 | float remainderf(float <[x]>, float <[y]>); |
---|
26 | |
---|
27 | DESCRIPTION |
---|
28 | <<remainder>> and <<remainderf>> find the remainder of |
---|
29 | <[x]>/<[y]>; this value is in the range -<[y]>/2 .. +<[y]>/2. |
---|
30 | |
---|
31 | RETURNS |
---|
32 | <<remainder>> returns the integer result as a double. |
---|
33 | |
---|
34 | PORTABILITY |
---|
35 | <<remainder>> is a System V release 4. |
---|
36 | <<remainderf>> is an extension. |
---|
37 | |
---|
38 | */ |
---|
39 | |
---|
40 | /* |
---|
41 | * wrapper remainder(x,p) |
---|
42 | */ |
---|
43 | |
---|
44 | #include "fdlibm.h" |
---|
45 | #include <errno.h> |
---|
46 | |
---|
47 | #ifndef _DOUBLE_IS_32BITS |
---|
48 | |
---|
49 | #ifdef __STDC__ |
---|
50 | double remainder(double x, double y) /* wrapper remainder */ |
---|
51 | #else |
---|
52 | double remainder(x,y) /* wrapper remainder */ |
---|
53 | double x,y; |
---|
54 | #endif |
---|
55 | { |
---|
56 | #ifdef _IEEE_LIBM |
---|
57 | return __ieee754_remainder(x,y); |
---|
58 | #else |
---|
59 | double z; |
---|
60 | struct exception exc; |
---|
61 | z = __ieee754_remainder(x,y); |
---|
62 | if(_LIB_VERSION == _IEEE_ || isnan(y)) return z; |
---|
63 | if(y==0.0) { |
---|
64 | /* remainder(x,0) */ |
---|
65 | exc.type = DOMAIN; |
---|
66 | exc.name = "remainder"; |
---|
67 | exc.err = 0; |
---|
68 | exc.arg1 = x; |
---|
69 | exc.arg2 = y; |
---|
70 | exc.retval = 0.0/0.0; |
---|
71 | if (_LIB_VERSION == _POSIX_) |
---|
72 | errno = EDOM; |
---|
73 | else if (!matherr(&exc)) { |
---|
74 | errno = EDOM; |
---|
75 | } |
---|
76 | if (exc.err != 0) |
---|
77 | errno = exc.err; |
---|
78 | return exc.retval; |
---|
79 | } else |
---|
80 | return z; |
---|
81 | #endif |
---|
82 | } |
---|
83 | |
---|
84 | #endif /* defined(_DOUBLE_IS_32BITS) */ |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | |
---|