29package com.jogamp.opengl.test.junit.math;
31import org.junit.Assert;
32import org.junit.FixMethodOrder;
34import org.junit.runners.MethodSorters;
36import com.jogamp.math.Binary16;
37import com.jogamp.opengl.test.junit.util.MiscUtils;
38import com.jogamp.opengl.test.junit.util.UITestCase;
40@FixMethodOrder(MethodSorters.NAME_ASCENDING)
43 static int stepping = 1;
44 static boolean verbose =
false;
52 System.out.println(
"-- Exponent identities");
53 for (
int e = -15; e <= 16; ++e) {
57 System.out.println(
"e: " + e +
", p: "+Integer.toHexString(p)+
", u: "+u);
59 Assert.assertEquals(e, u);
67 @SuppressWarnings(
"static-method") @Test
public void testInfinite()
73 for (
int i = 0; i <= 65535; i+=stepping) {
93 @SuppressWarnings(
"static-method") @Test
public
106 @SuppressWarnings(
"static-method") @Test
public
118 @SuppressWarnings(
"static-method") @Test
public
141 @SuppressWarnings(
"static-method") @Test
public
154 @SuppressWarnings(
"static-method") @Test
public void testNaN()
159 final char c = (char) n;
178 final double k = Double.NaN;
187 @SuppressWarnings(
"static-method") @Test
public
199 @SuppressWarnings(
"static-method") @Test
public
210 @SuppressWarnings(
"static-method") @Test
public
222 @SuppressWarnings(
"static-method") @Test
public
233 @SuppressWarnings({
"static-method",
"boxing" }) @Test
public
237 for (
int i = 0; i <= 65536; i+=stepping) {
242 System.out.println(String.format(
243 "packed: 0x%04x 0b%s in: %f unpacked: %f",
251 Assert.assertEquals(in, r, 0.0);
253 if ((i > 2048) && (i <= 4096)) {
254 Assert.assertTrue((r % 2) == 0);
256 if ((i > 4096) && (i <= 8192)) {
257 Assert.assertTrue((r % 4) == 0);
259 if ((i > 8192) && (i <= 16384)) {
260 Assert.assertTrue((r % 8) == 0);
262 if ((i > 16384) && (i <= 32768)) {
263 Assert.assertTrue((r % 16) == 0);
265 if ((i > 32768) && (i < 65536)) {
266 Assert.assertTrue((r % 32) == 0);
269 Assert.assertTrue(Double.isInfinite(r));
278 @SuppressWarnings({
"static-method",
"boxing" }) @Test
public
282 for (
int i = 0; i <= 65536; i+=stepping) {
283 final float f_in = i;
284 final double d_in = i;
289 System.out.println(
"i: " + i);
290 System.out.println(String.format(
291 "pack_f: 0x%04x 0b%s",
294 System.out.println(String.format(
295 "pack_d: 0x%04x 0b%s",
300 Assert.assertEquals(pf, pd);
310 final float k = Float.NaN;
319 @SuppressWarnings(
"static-method") @Test
public
331 @SuppressWarnings(
"static-method") @Test
public
342 @SuppressWarnings(
"static-method") @Test
public
354 @SuppressWarnings(
"static-method") @Test
public
365 @SuppressWarnings({
"static-method",
"boxing" }) @Test
public
369 for (
int i = 0; i <= 65536; i+=stepping) {
374 System.out.println(String.format(
375 "packed: 0x%04x 0b%s in: %f unpacked: %f",
383 Assert.assertEquals(in, r, 0.0);
385 if ((i > 2048) && (i <= 4096)) {
386 Assert.assertTrue((r % 2) == 0);
388 if ((i > 4096) && (i <= 8192)) {
389 Assert.assertTrue((r % 4) == 0);
391 if ((i > 8192) && (i <= 16384)) {
392 Assert.assertTrue((r % 8) == 0);
394 if ((i > 16384) && (i <= 32768)) {
395 Assert.assertTrue((r % 16) == 0);
397 if ((i > 32768) && (i < 65536)) {
398 Assert.assertTrue((r % 32) == 0);
401 Assert.assertTrue(Double.isInfinite(r));
410 @SuppressWarnings({
"static-method",
"boxing" }) @Test
public
414 for (
int i = 0; i <= 65536; i+=stepping) {
419 System.out.println(String.format(
420 "packed: 0x%04x 0b%s in: %f unpacked: %f",
428 Assert.assertEquals(in, r, 0.0);
430 if ((i > 2048) && (i <= 4096)) {
431 Assert.assertTrue((r % 2) == 0);
433 if ((i > 4096) && (i <= 8192)) {
434 Assert.assertTrue((r % 4) == 0);
436 if ((i > 8192) && (i <= 16384)) {
437 Assert.assertTrue((r % 8) == 0);
439 if ((i > 16384) && (i <= 32768)) {
440 Assert.assertTrue((r % 16) == 0);
442 if ((i > 32768) && (i < 65536)) {
443 Assert.assertTrue((r % 32) == 0);
446 Assert.assertTrue(Double.isInfinite(r));
455 @SuppressWarnings({
"static-method",
"boxing" }) @Test
public
459 for (
int i = 0; i <= 65536; i+=stepping) {
464 System.out.println(String.format(
465 "packed: 0x%04x 0b%s in: %f unpacked: %f",
472 Assert.assertEquals(in, r, 0.0);
474 if ((i > 2048) && (i <= 4096)) {
475 Assert.assertTrue((r % 2) == 0);
477 if ((i > 4096) && (i <= 8192)) {
478 Assert.assertTrue((r % 4) == 0);
480 if ((i > 8192) && (i <= 16384)) {
481 Assert.assertTrue((r % 8) == 0);
483 if ((i > 16384) && (i <= 32768)) {
484 Assert.assertTrue((r % 16) == 0);
486 if ((i > 32768) && (i < 65536)) {
487 Assert.assertTrue((r % 32) == 0);
490 Assert.assertTrue(Float.isInfinite(r));
501 System.out.println(
"-- Sign identities");
502 for (
int e = 0; e <= 1; ++e) {
506 System.out.println(
"e: " + e +
", p: "+Integer.toHexString(p)+
", u: "+u);
508 Assert.assertEquals(e, u);
516 @SuppressWarnings(
"static-method") @Test
public
520 System.out.println(
"-- Significand identities");
521 for (
int e = 0; e <= 1023; ++e) {
525 System.out.println(
"e: " + e +
", p: "+Integer.toHexString(p)+
", u: "+u);
527 Assert.assertEquals(e, u);
538 Assert.assertTrue(Double.isNaN(k));
545 @SuppressWarnings(
"static-method") @Test
public
549 Assert.assertTrue(Double.NEGATIVE_INFINITY ==
Binary16
557 @SuppressWarnings(
"static-method") @Test
public
568 @SuppressWarnings({
"static-method",
"boxing" }) @Test
public
572 final char one = 0x3C00;
574 System.out.println(String.format(
"0x%04x -> %f", (
int) one, r));
575 Assert.assertEquals(r, 1.0, 0.0);
582 @SuppressWarnings({
"static-method",
"boxing" }) @Test
public
586 final char one = 0xBC00;
588 System.out.println(String.format(
"0x%04x -> %f", (
int) one, r));
589 Assert.assertEquals(r, -1.0, 0.0);
596 @SuppressWarnings(
"static-method") @Test
public
600 Assert.assertTrue(Double.POSITIVE_INFINITY ==
Binary16
608 @SuppressWarnings(
"static-method") @Test
public
619 @SuppressWarnings({
"static-method",
"boxing" }) @Test
public
623 final char one = 0x4000;
625 System.out.println(String.format(
"%04x -> %f", (
int) one, r));
626 Assert.assertEquals(r, 2.0, 0.0);
633 @SuppressWarnings({
"static-method",
"boxing" }) @Test
public
637 final char one = 0xC000;
639 System.out.println(String.format(
"%04x -> %f", (
int) one, r));
640 Assert.assertEquals(r, -2.0, 0.0);
650 Assert.assertTrue(Float.isNaN(k));
657 @SuppressWarnings(
"static-method") @Test
public
661 Assert.assertTrue(Float.NEGATIVE_INFINITY ==
Binary16
669 @SuppressWarnings(
"static-method") @Test
public
680 @SuppressWarnings({
"static-method",
"boxing" }) @Test
public
684 final char one = 0x3C00;
686 System.out.println(String.format(
"0x%04x -> %f", (
int) one, r));
687 Assert.assertEquals(r, 1.0, 0.0);
694 @SuppressWarnings({
"static-method",
"boxing" }) @Test
public
698 final char one = 0xBC00;
700 System.out.println(String.format(
"0x%04x -> %f", (
int) one, r));
701 Assert.assertEquals(r, -1.0, 0.0);
704 public static void main(
final String args[]) {
705 for(
int i=0; i<args.length; i++) {
706 if(args[i].equals(
"-stepping")) {
708 }
else if(args[i].equals(
"-verbose")) {
static char packSetExponentUnbiasedUnchecked(final int e)
static char packSetSignificandUnchecked(final int s)
static final char NEGATIVE_INFINITY
The encoded form of negative infinity -∞.
static int unpackGetExponentUnbiased(final char k)
static char exampleNaN()
One possible not-a-number value.
static char packDouble(final double k)
static boolean isNaN(final char k)
Return true if the given packed binary16 value is not a number (NaN).
static final char POSITIVE_INFINITY
The encoded form of positive infinity ∞.
static final char NEGATIVE_ZERO
The encoded form of negative zero -0.
static int unpackGetSignificand(final char k)
static char packSetSignUnchecked(final int s)
static String toRawBinaryString(final char k)
Show the given raw packed binary16 value as a string of binary digits.
static char packFloat(final float k)
static double unpackDouble(final char k)
static boolean isInfinite(final char k)
Return true if the given packed binary16 value is infinite.
static final char POSITIVE_ZERO
The encoded form of positive zero 0.
static int unpackGetSign(final char k)
Retrieve the sign bit of the given packed binary16 value, as an integer in the range [0,...
static float unpackFloat(final char k)
void testInfinityNegativeExponent()
The unencoded exponent of infinity is 16.
void testPackFloatNegativeZero()
Packing negative zero results in negative zero.
void testSignIdentity()
Signs in the range [0, 1] are encoded and decoded correctly.
void testPackFloatNaN()
Packing NaN results in NaN.
void testInfinityNegativeSignificand()
The significand of infinity is 0.
void testUnpackDoubleOneNegative()
Unpacking -1.0 results in -1.0.
void testUnpackFloatNegativeZero()
Unpacking negative zero results in negative zero.
void testPackDoubleNegativeInfinity()
Packing negative infinity results in negative infinity.
void testUnpackFloatNaN()
Unpacking NaN results in NaN.
void testPackFloatPositiveInfinity()
Packing positive infinity results in positive infinity.
void testUnpackDoubleNegativeZero()
Unpacking negative zero results in negative zero.
void testUnpackDoubleTwoNegative()
Unpacking -2.0 results in -2.0.
void testInfinitySign()
The sign of positive infinity is 0.
void testPackUnpackFloat()
Integers in the range [0, 65520] should be representable.
void testUnpackDoublePositiveZero()
Unpacking positive zero results in positive zero.
void testSignificandIdentity()
Significands in the range [0, 1023] are encoded and decoded correctly.
void testPackFloatUnpackDouble()
Integers in the range [0, 65520] should be representable.
void testPackDoublePositiveInfinity()
Packing positive infinity results in positive infinity.
void testNaN()
NaN is NaN.
void testUnpackDoublePositiveInfinity()
Unpacking positive infinity results in positive infinity.
void testUnpackDoubleTwo()
Unpacking 2.0 results in 2.0.
void testPackDoubleUnpackFloat()
Integers in the range [0, 65520] should be representable.
void testUnpackFloatOne()
Unpacking 1.0 results in 1.0.
void testPackFloatPositiveZero()
Packing positive zero results in positive zero.
void testExponentIdentity()
Exponents in the range [-15, 16] are encoded and decoded correctly.
void testUnpackDoubleOne()
Unpacking 1.0 results in 1.0.
void testInfinite()
Infinities are infinite.
void testInfinitySignificand()
The significand of infinity is 0.
void testUnpackDoubleNegativeInfinity()
Unpacking negative infinity results in negative infinity.
static void main(final String args[])
void testPackFloatNegativeInfinity()
Packing negative infinity results in negative infinity.
void testInfinityNegativeSign()
The sign of negative infinity is 1.
void testPackFloatDoubleEquivalent()
Integers in the range [0, 65520] should be representable.
void testUnpackFloatOneNegative()
Unpacking -1.0 results in -1.0.
void testInfinityExponent()
The unencoded exponent of infinity is 16.
void testPackDoubleNegativeZero()
Packing negative zero results in negative zero.
void testUnpackDoubleNaN()
Unpacking NaN results in NaN.
void testPackUnpackDouble()
Integers in the range [0, 65520] should be representable.
void testPackDoubleNaN()
Packing NaN results in NaN.
void testUnpackFloatNegativeInfinity()
Unpacking negative infinity results in negative infinity.
void testPackDoublePositiveZero()
Packing positive zero results in positive zero.
static int atoi(final String str, final int def)