FSF GCC merge 02/23/03
[official-gcc.git] / libjava / java / lang / w_fmod.c
blobb6b36cb76ab93ea25d2fbc9802ac79f00ca89d3b
2 /* @(#)w_fmod.c 5.1 93/09/24 */
3 /*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
14 /*
15 FUNCTION
16 <<fmod>>, <<fmodf>>---floating-point remainder (modulo)
18 INDEX
19 fmod
20 INDEX
21 fmodf
23 ANSI_SYNOPSIS
24 #include <math.h>
25 double fmod(double <[x]>, double <[y]>)
26 float fmodf(float <[x]>, float <[y]>)
28 TRAD_SYNOPSIS
29 #include <math.h>
30 double fmod(<[x]>, <[y]>)
31 double (<[x]>, <[y]>);
33 float fmodf(<[x]>, <[y]>)
34 float (<[x]>, <[y]>);
36 DESCRIPTION
37 The <<fmod>> and <<fmodf>> functions compute the floating-point
38 remainder of <[x]>/<[y]> (<[x]> modulo <[y]>).
40 RETURNS
41 The <<fmod>> function returns the value
42 @ifinfo
43 <[x]>-<[i]>*<[y]>,
44 @end ifinfo
45 @tex
46 $x-i\times y$,
47 @end tex
48 for the largest integer <[i]> such that, if <[y]> is nonzero, the
49 result has the same sign as <[x]> and magnitude less than the
50 magnitude of <[y]>.
52 <<fmod(<[x]>,0)>> returns NaN, and sets <<errno>> to <<EDOM>>.
54 You can modify error treatment for these functions using <<matherr>>.
56 PORTABILITY
57 <<fmod>> is ANSI C. <<fmodf>> is an extension.
60 /*
61 * wrapper fmod(x,y)
64 #include "fdlibm.h"
65 #include <errno.h>
67 #ifndef _DOUBLE_IS_32BITS
69 #ifdef __STDC__
70 double fmod(double x, double y) /* wrapper fmod */
71 #else
72 double fmod(x,y) /* wrapper fmod */
73 double x,y;
74 #endif
76 #ifdef _IEEE_LIBM
77 return __ieee754_fmod(x,y);
78 #else
79 double z;
80 struct exception exc;
81 z = __ieee754_fmod(x,y);
82 if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z;
83 if(y==0.0) {
84 /* fmod(x,0) */
85 exc.type = DOMAIN;
86 exc.name = "fmod";
87 exc.arg1 = x;
88 exc.arg2 = y;
89 exc.err = 0;
90 if (_LIB_VERSION == _SVID_)
91 exc.retval = x;
92 else
93 exc.retval = 0.0/0.0;
94 if (_LIB_VERSION == _POSIX_)
95 errno = EDOM;
96 else if (!matherr(&exc)) {
97 errno = EDOM;
99 if (exc.err != 0)
100 errno = exc.err;
101 return exc.retval;
102 } else
103 return z;
104 #endif
107 #endif /* defined(_DOUBLE_IS_32BITS) */