4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1988 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 /* Special version adapted from libm for use in libc. */
31 static int n0
= 0, n1
= 1;
33 static double two52
= 4.503599627370496000E+15;
34 static double twom52
= 2.220446049250313081E-16;
37 setexception(int n
, double x
)
43 copysign(double x
, double y
)
45 long *px
= (long *) &x
;
46 long *py
= (long *) &y
;
47 px
[n0
] = (px
[n0
] & 0x7fffffff) | (py
[n0
] & 0x80000000);
54 long *px
= (long *) &x
;
63 long *px
= (long *) &x
;
64 return ((px
[n0
] & 0x7ff00000) != 0x7ff00000);
70 long *px
= (long *) &x
, k
;
71 k
= px
[n0
] & 0x7ff00000;
73 if ((px
[n1
] | (px
[n0
] & 0x7fffffff)) == 0)
77 return ((px
[n0
] & 0x7ff00000) >> 20) - 1075;
79 } else if (k
!= 0x7ff00000)
80 return (k
>> 20) - 1023;
86 scalbn(double x
, int n
)
88 long *px
= (long *) &x
, k
;
89 double twom54
= twom52
* 0.25;
90 k
= (px
[n0
] & 0x7ff00000) >> 20;
93 if ((px
[n1
] | (px
[n0
] & 0x7fffffff)) == 0)
97 k
= ((px
[n0
] & 0x7ff00000) >> 20) - 52;
101 return (setexception(2, x
));
103 return (setexception(1, x
));
105 return (setexception(2, x
));
107 return (setexception(1, x
));
109 px
[n0
] = (px
[n0
] & 0x800fffff) | (k
<< 20);
113 px
[n0
] = (px
[n0
] & 0x800fffff) | (k
<< 20);
118 fmod(double x
, double y
)
123 int finite(), ilogb();
124 double fabs(), scalbn(), copysign();
126 /* purge off exception values */
127 if (!finite(x
) || y
!= y
|| y
== 0.0) {
128 return ((x
* y
) / (x
* y
));
130 /* scale and subtract to get the remainder */
139 z
= scalbn(y
, nr
- ny
- 1);
149 return (copysign(r
, x
));