source: trunk/libs/newlib/src/newlib/libm/math/w_fmod.c @ 567

Last change on this file since 567 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.1 KB
Line 
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/*
15FUNCTION
16<<fmod>>, <<fmodf>>---floating-point remainder (modulo)
17
18INDEX
19fmod
20INDEX
21fmodf
22
23SYNOPSIS
24#include <math.h>
25double fmod(double <[x]>, double <[y]>);
26float fmodf(float <[x]>, float <[y]>);
27
28DESCRIPTION
29The <<fmod>> and <<fmodf>> functions compute the floating-point
30remainder of <[x]>/<[y]> (<[x]> modulo <[y]>).
31
32RETURNS
33The <<fmod>> function returns the value
34@ifnottex
35<[x]>-<[i]>*<[y]>,
36@end ifnottex
37@tex
38$x-i\times y$,
39@end tex
40for the largest integer <[i]> such that, if <[y]> is nonzero, the
41result has the same sign as <[x]> and magnitude less than the
42magnitude of <[y]>.
43
44<<fmod(<[x]>,0)>> returns NaN, and sets <<errno>> to <<EDOM>>.
45
46You can modify error treatment for these functions using <<matherr>>.
47
48PORTABILITY
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) */
Note: See TracBrowser for help on using the repository browser.