make these only work for things that have EXT_ foo definitions.diff -r1.1 -r1.2 src/lib/libm/src/s_nearbyint.c
(christos)
--- src/lib/libm/src/s_nearbyint.c 2013/02/09 19:37:48 1.1
+++ src/lib/libm/src/s_nearbyint.c 2013/02/09 23:14:44 1.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: s_nearbyint.c,v 1.1 2013/02/09 19:37:48 christos Exp $ */ | 1 | /* $NetBSD: s_nearbyint.c,v 1.2 2013/02/09 23:14:44 christos Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> | 4 | * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -20,42 +20,45 @@ | @@ -20,42 +20,45 @@ | |||
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | * SUCH DAMAGE. | 26 | * SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include <sys/cdefs.h> | 29 | #include <sys/cdefs.h> | |
30 | #if 0 | 30 | #if 0 | |
31 | __FBSDID("$FreeBSD: src/lib/msun/src/s_nearbyint.c,v 1.2 2008/01/14 02:12:06 das Exp $"); | 31 | __FBSDID("$FreeBSD: src/lib/msun/src/s_nearbyint.c,v 1.2 2008/01/14 02:12:06 das Exp $"); | |
32 | #else | 32 | #else | |
33 | __RCSID("$NetBSD: s_nearbyint.c,v 1.1 2013/02/09 19:37:48 christos Exp $"); | 33 | __RCSID("$NetBSD: s_nearbyint.c,v 1.2 2013/02/09 23:14:44 christos Exp $"); | |
34 | #endif | 34 | #endif | |
35 | 35 | |||
36 | #include <machine/ieee.h> | |||
36 | #include <fenv.h> | 37 | #include <fenv.h> | |
37 | #include <math.h> | 38 | #include <math.h> | |
38 | 39 | |||
39 | /* | 40 | /* | |
40 | * We save and restore the floating-point environment to avoid raising | 41 | * We save and restore the floating-point environment to avoid raising | |
41 | * an inexact exception. We can get away with using fesetenv() | 42 | * an inexact exception. We can get away with using fesetenv() | |
42 | * instead of feclearexcept()/feupdateenv() to restore the environment | 43 | * instead of feclearexcept()/feupdateenv() to restore the environment | |
43 | * because the only exception defined for rint() is overflow, and | 44 | * because the only exception defined for rint() is overflow, and | |
44 | * rounding can't overflow as long as emax >= p. | 45 | * rounding can't overflow as long as emax >= p. | |
45 | */ | 46 | */ | |
46 | #define DECL(type, fn, rint) \ | 47 | #define DECL(type, fn, rint) \ | |
47 | type \ | 48 | type \ | |
48 | fn(type x) \ | 49 | fn(type x) \ | |
49 | { \ | 50 | { \ | |
50 | type ret; \ | 51 | type ret; \ | |
51 | fenv_t env; \ | 52 | fenv_t env; \ | |
52 | \ | 53 | \ | |
53 | fegetenv(&env); \ | 54 | fegetenv(&env); \ | |
54 | ret = rint(x); \ | 55 | ret = rint(x); \ | |
55 | fesetenv(&env); \ | 56 | fesetenv(&env); \ | |
56 | return (ret); \ | 57 | return (ret); \ | |
57 | } | 58 | } | |
58 | 59 | |||
59 | DECL(double, nearbyint, rint) | 60 | DECL(double, nearbyint, rint) | |
60 | DECL(float, nearbyintf, rintf) | 61 | DECL(float, nearbyintf, rintf) | |
62 | #ifdef EXT_FRACBITS | |||
61 | DECL(long double, nearbyintl, rintl) | 63 | DECL(long double, nearbyintl, rintl) | |
64 | #endif |
--- src/lib/libm/src/s_nexttowardf.c 2013/02/09 20:19:13 1.2
+++ src/lib/libm/src/s_nexttowardf.c 2013/02/09 23:14:44 1.3
@@ -1,66 +1,66 @@ | @@ -1,66 +1,66 @@ | |||
1 | /* $NetBSD: s_nexttowardf.c,v 1.2 2013/02/09 20:19:13 christos Exp $ */ | 1 | /* $NetBSD: s_nexttowardf.c,v 1.3 2013/02/09 23:14:44 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * ==================================================== | 4 | * ==================================================== | |
5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | |
6 | * | 6 | * | |
7 | * Developed at SunPro, a Sun Microsystems, Inc. business. | 7 | * Developed at SunPro, a Sun Microsystems, Inc. business. | |
8 | * Permission to use, copy, modify, and distribute this | 8 | * Permission to use, copy, modify, and distribute this | |
9 | * software is freely granted, provided that this notice | 9 | * software is freely granted, provided that this notice | |
10 | * is preserved. | 10 | * is preserved. | |
11 | * ==================================================== | 11 | * ==================================================== | |
12 | */ | 12 | */ | |
13 | 13 | |||
14 | #include <sys/cdefs.h> | 14 | #include <sys/cdefs.h> | |
15 | #if 0 | 15 | #if 0 | |
16 | __FBSDID("$FreeBSD: src/lib/msun/src/s_nexttowardf.c,v 1.3 2011/02/10 07:38:38 das Exp $"); | 16 | __FBSDID("$FreeBSD: src/lib/msun/src/s_nexttowardf.c,v 1.3 2011/02/10 07:38:38 das Exp $"); | |
17 | #else | 17 | #else | |
18 | __RCSID("$NetBSD: s_nexttowardf.c,v 1.2 2013/02/09 20:19:13 christos Exp $"); | 18 | __RCSID("$NetBSD: s_nexttowardf.c,v 1.3 2013/02/09 23:14:44 christos Exp $"); | |
19 | #endif | 19 | #endif | |
20 | 20 | |||
21 | #include <string.h> | |||
21 | #include <float.h> | 22 | #include <float.h> | |
23 | #include <machine/ieee.h> | |||
22 | 24 | |||
23 | #include "math.h" | 25 | #include "math.h" | |
24 | #include "math_private.h" | 26 | #include "math_private.h" | |
25 | 27 | |||
26 | #ifdef EXT_EXP_INFNAN | 28 | #ifdef EXT_EXP_INFNAN | |
27 | float | 29 | float | |
28 | nexttowardf(float x, long double y) | 30 | nexttowardf(float x, long double y) | |
29 | { | 31 | { | |
30 | volatile float t; | 32 | volatile float t; | |
31 | int32_t hx,ix; | 33 | int32_t hx,ix; | |
32 | union ieee_ext_u uy; | 34 | union ieee_ext_u uy; | |
33 | 35 | |||
34 | GET_FLOAT_WORD(hx,x); | 36 | GET_FLOAT_WORD(hx,x); | |
35 | ix = hx&0x7fffffff; /* |x| */ | 37 | ix = hx&0x7fffffff; /* |x| */ | |
36 | 38 | |||
37 | memset(&u, 0, sizeof u); | 39 | memset(&uy, 0, sizeof(uy)); | |
38 | uy.extu_ld = y; | 40 | uy.extu_ld = y; | |
39 | uy.extu_ext.ext_frach &= ~0x80000000; | 41 | uy.extu_ext.ext_frach &= ~0x80000000; | |
40 | 42 | |||
41 | union ieee_single_u u[2]; | |||
42 | ||||
43 | if((ix>0x7f800000) || | 43 | if((ix>0x7f800000) || | |
44 | (uy.extu_ext.ext_exp == EXT_EXP_INFNAN && | 44 | (uy.extu_ext.ext_exp == EXT_EXP_INFNAN && | |
45 | (uy.extu_ext.ext_frach | uy.extu_ext.ext_fracl) != 0) | 45 | (uy.extu_ext.ext_frach | uy.extu_ext.ext_fracl) != 0)) | |
46 | return x+y; /* x or y is nan */ | 46 | return x+y; /* x or y is nan */ | |
47 | if(x==y) return (float)y; /* x=y, return y */ | 47 | if(x==y) return (float)y; /* x=y, return y */ | |
48 | if(ix==0) { /* x == 0 */ | 48 | if(ix==0) { /* x == 0 */ | |
49 | SET_FLOAT_WORD(x,(uy.extu_ext.ext_sign<<31)|1);/* return +-minsubnormal */ | 49 | SET_FLOAT_WORD(x,(uy.extu_ext.ext_sign<<31)|1);/* return +-minsubnormal */ | |
50 | t = x*x; | 50 | t = x*x; | |
51 | if(t==x) return t; else return x; /* raise underflow flag */ | 51 | if(t==x) return t; else return x; /* raise underflow flag */ | |
52 | } | 52 | } | |
53 | if(hx>=0 ^ x < y) /* x -= ulp */ | 53 | if((hx >= 0) ^ (x < y)) /* x -= ulp */ | |
54 | hx -= 1; | 54 | hx -= 1; | |
55 | else /* x += ulp */ | 55 | else /* x += ulp */ | |
56 | hx += 1; | 56 | hx += 1; | |
57 | ix = hx&0x7f800000; | 57 | ix = hx&0x7f800000; | |
58 | if(ix>=0x7f800000) return x+x; /* overflow */ | 58 | if(ix>=0x7f800000) return x+x; /* overflow */ | |
59 | if(ix<0x00800000) { /* underflow */ | 59 | if(ix<0x00800000) { /* underflow */ | |
60 | t = x*x; | 60 | t = x*x; | |
61 | if(t!=x) { /* raise underflow flag */ | 61 | if(t!=x) { /* raise underflow flag */ | |
62 | SET_FLOAT_WORD(x,hx); | 62 | SET_FLOAT_WORD(x,hx); | |
63 | return x; | 63 | return x; | |
64 | } | 64 | } | |
65 | } | 65 | } | |
66 | SET_FLOAT_WORD(x,hx); | 66 | SET_FLOAT_WORD(x,hx); |
--- src/lib/libm/src/s_rintl.c 2013/02/09 22:33:13 1.2
+++ src/lib/libm/src/s_rintl.c 2013/02/09 23:14:44 1.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: s_rintl.c,v 1.2 2013/02/09 22:33:13 christos Exp $ */ | 1 | /* $NetBSD: s_rintl.c,v 1.3 2013/02/09 23:14:44 christos Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG> | 4 | * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -20,31 +20,34 @@ | @@ -20,31 +20,34 @@ | |||
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | * SUCH DAMAGE. | 26 | * SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include <sys/cdefs.h> | 29 | #include <sys/cdefs.h> | |
30 | #if 0 | 30 | #if 0 | |
31 | __FBSDID("$FreeBSD: src/lib/msun/src/s_rintl.c,v 1.5 2008/02/22 11:59:05 bde Exp $"); | 31 | __FBSDID("$FreeBSD: src/lib/msun/src/s_rintl.c,v 1.5 2008/02/22 11:59:05 bde Exp $"); | |
32 | #else | 32 | #else | |
33 | __RCSID("$NetBSD: s_rintl.c,v 1.2 2013/02/09 22:33:13 christos Exp $"); | 33 | __RCSID("$NetBSD: s_rintl.c,v 1.3 2013/02/09 23:14:44 christos Exp $"); | |
34 | #endif | 34 | #endif | |
35 | 35 | |||
36 | #include <float.h> | 36 | #include <float.h> | |
37 | #include <math.h> | 37 | #include <machine/ieee.h> | |
38 | ||||
39 | #include "math.h" | |||
40 | #include "math_private.h" | |||
38 | 41 | |||
39 | #ifdef EXT_EXP_BIAS | 42 | #ifdef EXT_EXP_BIAS | |
40 | static const float | 43 | static const float | |
41 | shift[2] = { | 44 | shift[2] = { | |
42 | #if EXT_FRACBITS == 64 | 45 | #if EXT_FRACBITS == 64 | |
43 | 0x1.0p63, -0x1.0p63 | 46 | 0x1.0p63, -0x1.0p63 | |
44 | #elif EXT_FRACBITS == 113 | 47 | #elif EXT_FRACBITS == 113 | |
45 | 0x1.0p112, -0x1.0p112 | 48 | 0x1.0p112, -0x1.0p112 | |
46 | #else | 49 | #else | |
47 | #error "Unsupported long double format" | 50 | #error "Unsupported long double format" | |
48 | #endif | 51 | #endif | |
49 | }; | 52 | }; | |
50 | static const float zero[2] = { 0.0, -0.0 }; | 53 | static const float zero[2] = { 0.0, -0.0 }; |