IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
s_floor.cs
Go to the documentation of this file.
1/*
2 * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26/*
27 * floor(x)
28 * Return x rounded toward -inf to integral value
29 * Method:
30 * Bit twiddling.
31 * Exception:
32 * Inexact flag raised if x not equal to floor(x).
33 */
34using unsigned = System.UInt32;
35
37{
38 static partial class fdlibm
39 {
40 internal static double floor(double x)
41 {
42 const double huge = 1.0e300;
43
44 int i0, i1, j0;
45 unsigned i, j;
46 i0 = __HI(x);
47 i1 = __LO(x);
48 j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
49 if (j0 < 20)
50 {
51 if (j0 < 0)
52 { /* raise inexact if x != 0 */
53 if (huge + x > 0.0)
54 {/* return 0*sign(x) if |x|<1 */
55 if (i0 >= 0) { i0 = i1 = 0; }
56 else if (((i0 & 0x7fffffff) | i1) != 0)
57 { i0 = unchecked((int)0xbff00000); i1 = 0; }
58 }
59 }
60 else
61 {
62 i = (unsigned)((0x000fffff) >> j0);
63 if (((i0 & (int)i) | i1) == 0) return x; /* x is integral */
64 if (huge + x > 0.0)
65 { /* raise inexact flag */
66 if (i0 < 0) i0 += (0x00100000) >> j0;
67 i0 &= (~(int)i); i1 = 0;
68 }
69 }
70 }
71 else if (j0 > 51)
72 {
73 if (j0 == 0x400) return x + x; /* inf or NaN */
74 else return x; /* x is integral */
75 }
76 else
77 {
78 i = ((unsigned)(0xffffffff)) >> (j0 - 20);
79 if ((i1 & i) == 0) return x; /* x is integral */
80 if (huge + x > 0.0)
81 { /* raise inexact flag */
82 if (i0 < 0)
83 {
84 if (j0 == 20) i0 += 1;
85 else
86 {
87 j = (unsigned)(i1 + (1 << (52 - j0)));
88 if (j < i1) i0 += 1; /* got a carry */
89 i1 = (int)j;
90 }
91 }
92 i1 &= (~(int)i);
93 }
94 }
95 x = __HI(x, i0);
96 x = __LO(x, i1);
97 return x;
98 }
99 }
100}
System.UInt32 unsigned
Definition e_pow.cs:70