JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
Binary32.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>binary32</code> (float) values.
33 */
34
35public final class Binary32
36{
37 static final int NEGATIVE_ZERO_BITS;
38 static final int MASK_SIGN;
39 static final int MASK_EXPONENT;
40 static final int MASK_SIGNIFICAND;
41 static final int BIAS;
42
43 static {
44 NEGATIVE_ZERO_BITS = 0x80000000;
45 MASK_SIGN = 0x80000000;
46 MASK_EXPONENT = 0x7ff00000;
47 MASK_SIGNIFICAND = 0x7fffff;
48 BIAS = 127;
49 }
50
51 /**
52 * <p>
53 * Extract and unbias the exponent of the given packed <code>float</code>
54 * value.
55 * </p>
56 * <p>
57 * The exponent is encoded <i>biased</i> as a number in the range
58 * <code>[0, 255]</code>, with <code>0</code> indicating that the number is
59 * <i>subnormal</i> and <code>[1, 254]</code> denoting the actual exponent
60 * plus {@link #BIAS}. Infinite and <code>NaN</code> values always have a
61 * biased exponent of <code>255</code>.
62 * </p>
63 * <p>
64 * This function will therefore return:
65 * </p>
66 * <ul>
67 * <li>
68 * <code>0 - {@link #BIAS} = -127</code> iff the input is a <i>subnormal</i>
69 * number.</li>
70 * <li>An integer in the range
71 * <code>[1 - {@link #BIAS}, 254 - {@link #BIAS}] = [-126, 127]</code> iff
72 * the input is a <i>normal</i> number.</li>
73 * <li>
74 * <code>255 - {@link #BIAS} = 128</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 int unpackGetExponentUnbiased(
83 final float d)
84 {
85 final int b = Float.floatToRawIntBits(d);
86 final int em = b & Binary32.MASK_EXPONENT;
87 final int es = em >> 23;
88 return es - Binary32.BIAS;
89 }
90
91 /**
92 * <p>
93 * Return the sign of the given float value.
94 * </p>
95 */
96
97 public static int unpackGetSign(
98 final float d)
99 {
100 final int b = Float.floatToRawIntBits(d);
101 return ((b & Binary32.MASK_SIGN) >> 31) & 1;
102 }
103
104 /**
105 * <p>
106 * Return the significand of the given float value.
107 * </p>
108 */
109
110 public static int unpackGetSignificand(
111 final float d)
112 {
113 final int b = Float.floatToRawIntBits(d);
114 return b & Binary32.MASK_SIGNIFICAND;
115 }
116}
Functions for interrogating binary32 (float) values.
Definition: Binary32.java:36
static int unpackGetSign(final float d)
Definition: Binary32.java:97
static int unpackGetExponentUnbiased(final float d)
Definition: Binary32.java:82
static int unpackGetSignificand(final float d)
Definition: Binary32.java:110