JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
Binary64.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.math;
30
31/**
32 * Functions for interrogating <code>binary64</code> (double) values.
33 */
34
35public final class Binary64
36{
37 static final long NEGATIVE_ZERO_BITS;
38 static final long MASK_SIGN;
39 static final long MASK_EXPONENT;
40 static final long MASK_SIGNIFICAND;
41 static final long BIAS;
42
43 static {
44 NEGATIVE_ZERO_BITS = 0x8000000000000000L;
45 MASK_SIGN = 0x8000000000000000L;
46 MASK_EXPONENT = 0x7ff0000000000000L;
47 MASK_SIGNIFICAND = 0x000fffffffffffffL;
48 BIAS = 1023;
49 }
50
51 /**
52 * <p>
53 * Extract and unbias the exponent of the given packed <code>double</code>
54 * value.
55 * </p>
56 * <p>
57 * The exponent is encoded <i>biased</i> as a number in the range
58 * <code>[0, 2047]</code>, with <code>0</code> indicating that the number is
59 * <i>subnormal</i> and <code>[1, 2046]</code> denoting the actual exponent
60 * plus {@link #BIAS}. Infinite and <code>NaN</code> values always have a
61 * biased exponent of <code>2047</code>.
62 * </p>
63 * <p>
64 * This function will therefore return:
65 * </p>
66 * <ul>
67 * <li>
68 * <code>0 - {@link #BIAS} = -1023</code> iff the input is a
69 * <i>subnormal</i> number.</li>
70 * <li>An integer in the range
71 * <code>[1 - {@link #BIAS}, 2046 - {@link #BIAS}] = [-1022, 1023]</code>
72 * iff the input is a <i>normal</i> number.</li>
73 * <li>
74 * <code>2047 - {@link #BIAS} = 1024</code> iff the input is
75 * {@link #POSITIVE_INFINITY}, {@link #NEGATIVE_INFINITY}, or
76 * <code>NaN</code>.</li>
77 * </ul>
78 *
79 * @see #packSetExponentUnbiasedUnchecked(int)
80 */
81
82 public static long unpackGetExponentUnbiased(
83 final double d)
84 {
85 final long b = Double.doubleToRawLongBits(d);
86 final long em = b & Binary64.MASK_EXPONENT;
87 final long es = em >> 52;
88 return es - Binary64.BIAS;
89 }
90
91 /**
92 * <p>
93 * Return the significand of the given double value.
94 * </p>
95 */
96
97 public static long unpackGetSignificand(
98 final double d)
99 {
100 final long b = Double.doubleToRawLongBits(d);
101 return b & Binary64.MASK_SIGNIFICAND;
102 }
103
104 /**
105 * <p>
106 * Return the sign of the given double value.
107 * </p>
108 */
109
110 public static long unpackGetSign(
111 final double d)
112 {
113 final long b = Double.doubleToRawLongBits(d);
114 return ((b & Binary64.MASK_SIGN) >> 63) & 1;
115 }
116}
Functions for interrogating binary64 (double) values.
Definition: Binary64.java:36
static long unpackGetSign(final double d)
Definition: Binary64.java:110
static long unpackGetExponentUnbiased(final double d)
Definition: Binary64.java:82
static long unpackGetSignificand(final double d)
Definition: Binary64.java:97