author | jlaskey |
Thu, 14 Nov 2019 12:33:47 -0400 | |
branch | jlaskey-prng |
changeset 59084 | b8fb85ee91e9 |
parent 49051 | f05f4b5cea20 |
permissions | -rw-r--r-- |
35055
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
1 |
/* |
49051
f05f4b5cea20
8198558: Windows does not build without precompiled headers
stuefe
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
35055
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
4 |
* |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
8 |
* |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
13 |
* accompanied this code). |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
14 |
* |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
18 |
* |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
21 |
* questions. |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
22 |
* |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
23 |
*/ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
24 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
49051
f05f4b5cea20
8198558: Windows does not build without precompiled headers
stuefe
parents:
47216
diff
changeset
|
26 |
#include "runtime/sharedRuntime.hpp" |
35055
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
27 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
28 |
#ifdef _WIN64 |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
29 |
// These are copied defines from fdlibm.h, this allows us to keep the code |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
30 |
// the same as in the JDK, for easier maintenance. |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
31 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
32 |
#define __HI(x) *(1+(int*)&x) |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
33 |
#define __LO(x) *(int*)&x |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
34 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
35 |
// This code is a copy of __ieee754_fmod() from the JDK's libfdlibm and is |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
36 |
// used as a workaround for issues with the Windows x64 CRT implementation |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
37 |
// of fmod. Microsoft has acknowledged that this is an issue in Visual Studio |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
38 |
// 2012 and forward, but has not provided a time frame for a fix other than that |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
39 |
// it'll not be fixed in Visual Studio 2013 or 2015. |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
40 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
41 |
static const double one = 1.0, Zero[] = { 0.0, -0.0, }; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
42 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
43 |
double SharedRuntime::fmod_winx64(double x, double y) |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
44 |
{ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
45 |
int n, hx, hy, hz, ix, iy, sx, i; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
46 |
unsigned lx, ly, lz; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
47 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
48 |
hx = __HI(x); /* high word of x */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
49 |
lx = __LO(x); /* low word of x */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
50 |
hy = __HI(y); /* high word of y */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
51 |
ly = __LO(y); /* low word of y */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
52 |
sx = hx & 0x80000000; /* sign of x */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
53 |
hx ^= sx; /* |x| */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
54 |
hy &= 0x7fffffff; /* |y| */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
55 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
56 |
#pragma warning( disable : 4146 ) |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
57 |
/* purge off exception values */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
58 |
if ((hy | ly) == 0 || (hx >= 0x7ff00000) || /* y=0,or x not finite */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
59 |
((hy | ((ly | -ly) >> 31))>0x7ff00000)) /* or y is NaN */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
60 |
#pragma warning( default : 4146 ) |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
61 |
return (x*y) / (x*y); |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
62 |
if (hx <= hy) { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
63 |
if ((hx<hy) || (lx<ly)) return x; /* |x|<|y| return x */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
64 |
if (lx == ly) |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
65 |
return Zero[(unsigned)sx >> 31]; /* |x|=|y| return x*0*/ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
66 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
67 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
68 |
/* determine ix = ilogb(x) */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
69 |
if (hx<0x00100000) { /* subnormal x */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
70 |
if (hx == 0) { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
71 |
for (ix = -1043, i = lx; i>0; i <<= 1) ix -= 1; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
72 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
73 |
else { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
74 |
for (ix = -1022, i = (hx << 11); i>0; i <<= 1) ix -= 1; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
75 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
76 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
77 |
else ix = (hx >> 20) - 1023; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
78 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
79 |
/* determine iy = ilogb(y) */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
80 |
if (hy<0x00100000) { /* subnormal y */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
81 |
if (hy == 0) { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
82 |
for (iy = -1043, i = ly; i>0; i <<= 1) iy -= 1; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
83 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
84 |
else { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
85 |
for (iy = -1022, i = (hy << 11); i>0; i <<= 1) iy -= 1; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
86 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
87 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
88 |
else iy = (hy >> 20) - 1023; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
89 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
90 |
/* set up {hx,lx}, {hy,ly} and align y to x */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
91 |
if (ix >= -1022) |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
92 |
hx = 0x00100000 | (0x000fffff & hx); |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
93 |
else { /* subnormal x, shift x to normal */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
94 |
n = -1022 - ix; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
95 |
if (n <= 31) { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
96 |
hx = (hx << n) | (lx >> (32 - n)); |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
97 |
lx <<= n; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
98 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
99 |
else { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
100 |
hx = lx << (n - 32); |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
101 |
lx = 0; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
102 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
103 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
104 |
if (iy >= -1022) |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
105 |
hy = 0x00100000 | (0x000fffff & hy); |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
106 |
else { /* subnormal y, shift y to normal */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
107 |
n = -1022 - iy; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
108 |
if (n <= 31) { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
109 |
hy = (hy << n) | (ly >> (32 - n)); |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
110 |
ly <<= n; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
111 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
112 |
else { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
113 |
hy = ly << (n - 32); |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
114 |
ly = 0; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
115 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
116 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
117 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
118 |
/* fix point fmod */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
119 |
n = ix - iy; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
120 |
while (n--) { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
121 |
hz = hx - hy; lz = lx - ly; if (lx<ly) hz -= 1; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
122 |
if (hz<0){ hx = hx + hx + (lx >> 31); lx = lx + lx; } |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
123 |
else { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
124 |
if ((hz | lz) == 0) /* return sign(x)*0 */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
125 |
return Zero[(unsigned)sx >> 31]; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
126 |
hx = hz + hz + (lz >> 31); lx = lz + lz; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
127 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
128 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
129 |
hz = hx - hy; lz = lx - ly; if (lx<ly) hz -= 1; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
130 |
if (hz >= 0) { hx = hz; lx = lz; } |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
131 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
132 |
/* convert back to floating value and restore the sign */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
133 |
if ((hx | lx) == 0) /* return sign(x)*0 */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
134 |
return Zero[(unsigned)sx >> 31]; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
135 |
while (hx<0x00100000) { /* normalize x */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
136 |
hx = hx + hx + (lx >> 31); lx = lx + lx; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
137 |
iy -= 1; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
138 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
139 |
if (iy >= -1022) { /* normalize output */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
140 |
hx = ((hx - 0x00100000) | ((iy + 1023) << 20)); |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
141 |
__HI(x) = hx | sx; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
142 |
__LO(x) = lx; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
143 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
144 |
else { /* subnormal output */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
145 |
n = -1022 - iy; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
146 |
if (n <= 20) { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
147 |
lx = (lx >> n) | ((unsigned)hx << (32 - n)); |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
148 |
hx >>= n; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
149 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
150 |
else if (n <= 31) { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
151 |
lx = (hx << (32 - n)) | (lx >> n); hx = sx; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
152 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
153 |
else { |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
154 |
lx = hx >> (n - 32); hx = sx; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
155 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
156 |
__HI(x) = hx | sx; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
157 |
__LO(x) = lx; |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
158 |
x *= one; /* create necessary signal */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
159 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
160 |
return x; /* exact output */ |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
161 |
} |
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
162 |
|
a4cf2927e727
8015396: double a%b returns NaN for some (a,b) (|a| < inf, |b|>0)
ctornqvi
parents:
diff
changeset
|
163 |
#endif |