FC18: Moved NAN to last for better bit pattern layout
This commit is contained in:
parent
49150be3b1
commit
37992ce50a
3 changed files with 163 additions and 17 deletions
|
|
@ -46,50 +46,52 @@ public enum FCFlameNumberTaste {
|
|||
INFINITY_NEGATIVE_CARRY,
|
||||
|
||||
/// 1000
|
||||
FLAG_NAN,
|
||||
/// 1001
|
||||
FLAG_ROUNDED,
|
||||
/// 1010
|
||||
/// 1001
|
||||
FLAG_CLAMPED,
|
||||
/// 1011
|
||||
/// 1010
|
||||
FLAG_INEXACT,
|
||||
/// 1100
|
||||
/// 1011
|
||||
FLAG_UDERFLOW,
|
||||
/// 1101
|
||||
/// 1100
|
||||
FLAG_OVERFLOW,
|
||||
/// 1110
|
||||
/// 1101
|
||||
FLAG_DIV_BY_ZERO,
|
||||
/// 1111
|
||||
/// 1110
|
||||
FLAG_INVALID_OPERATION,
|
||||
/// 1111
|
||||
FLAG_NAN,
|
||||
;
|
||||
private static final FCFlameNumberTaste[] VALUES = values();
|
||||
private static final int CHOCO_LETTER_ZERO = NUMBER_POSITIVE.ordinal();
|
||||
private static final int CHOCO_HEAT_CYCLE_STEP = NUMBER_POSITIVE_CARRY.ordinal();
|
||||
private static final int CHOCO_MASK_BIT_1000 = FLAG_NAN.ordinal();
|
||||
private static final int CHOCO_MASK_BIT_0100 = INFINITY_POSITIVE.ordinal();
|
||||
private static final int CHOCO_MASK_BIT_0000 = NUMBER_POSITIVE.ordinal();
|
||||
private static final int CHOCO_MASK_BIT_0001 = NUMBER_NEGATIVE.ordinal();
|
||||
private static final int CHOCO_MASK_BIT_0100 = INFINITY_POSITIVE.ordinal();
|
||||
private static final int CHOCO_MASK_BIT_1000 = FLAG_ROUNDED.ordinal();
|
||||
private static final int CHOCO_MASK_BIT_1001 = FLAG_CLAMPED.ordinal();
|
||||
private static final int CHOCO_MASK_BIT_1100 = FLAG_OVERFLOW.ordinal();
|
||||
|
||||
private FCFlameNumberTaste() {
|
||||
}
|
||||
|
||||
public boolean numberValid() {
|
||||
return CHOCO_LETTER_ZERO == (ordinal() & CHOCO_MASK_BIT_1000);
|
||||
return CHOCO_MASK_BIT_0000 == (ordinal() & CHOCO_MASK_BIT_1000);
|
||||
}
|
||||
|
||||
public boolean numberValidInteger() {
|
||||
return numberValid() && CHOCO_LETTER_ZERO == (ordinal() & CHOCO_MASK_BIT_0100);
|
||||
return CHOCO_MASK_BIT_0000 == (ordinal() & CHOCO_MASK_BIT_1100);
|
||||
}
|
||||
|
||||
public boolean numberValidInfinity() {
|
||||
return numberValid() && CHOCO_LETTER_ZERO != (ordinal() & CHOCO_MASK_BIT_0100);
|
||||
return CHOCO_MASK_BIT_0100 == (ordinal() & CHOCO_MASK_BIT_1100);
|
||||
}
|
||||
|
||||
public boolean statusSignPositive() {
|
||||
return false == statusSignNegative();
|
||||
return CHOCO_MASK_BIT_0001 != (ordinal() & CHOCO_MASK_BIT_1001);
|
||||
}
|
||||
|
||||
public boolean statusSignNegative() {
|
||||
return numberValid() && CHOCO_LETTER_ZERO != (ordinal() & CHOCO_MASK_BIT_0001);
|
||||
return CHOCO_MASK_BIT_0001 == (ordinal() & CHOCO_MASK_BIT_1001);
|
||||
}
|
||||
|
||||
public boolean statusCarryLess() {
|
||||
|
|
@ -101,7 +103,7 @@ public enum FCFlameNumberTaste {
|
|||
}
|
||||
|
||||
public boolean statusFlag() {
|
||||
return false == numberValid();
|
||||
return CHOCO_MASK_BIT_1000 == (ordinal() & CHOCO_MASK_BIT_1000);
|
||||
}
|
||||
|
||||
public FCFlameNumberTaste chocoRemeltUp() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2014, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.fc18.zion7.flame4;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests four corner freman suite fittings
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Se[ 5, 2025
|
||||
*/
|
||||
public class FCFlameFremanSuitTest {
|
||||
|
||||
@Test
|
||||
public void testDataSize() throws Exception {
|
||||
Assertions.assertEquals(768, FCFlameFremanChocoBase8.CHOCO_2304.octals());
|
||||
Assertions.assertEquals(6, FCFlameFremanLegoBase8.LEGO_0018.octals());
|
||||
Assertions.assertEquals(8, FCFlameFremanSignedBase2.SIGNED_0064.bytes());
|
||||
Assertions.assertEquals(2, FCFlameFremanLegoBase2.LEGO_0016.bytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuitChocoBase8() throws Exception {
|
||||
Arrays.asList(FCFlameFremanChocoBase8.values()).forEach(v -> checkSuite(v));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuitLegoBase8() throws Exception {
|
||||
Arrays.asList(FCFlameFremanLegoBase8.values()).forEach(v -> checkSuite(v));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuitSignedBase2() throws Exception {
|
||||
Arrays.asList(FCFlameFremanSignedBase2.values()).forEach(v -> checkSuite(v));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuitLegoBase2() throws Exception {
|
||||
Arrays.asList(FCFlameFremanLegoBase2.values()).forEach(v -> checkSuite(v));
|
||||
}
|
||||
|
||||
|
||||
private void checkSuite(FCFlameFremanSuit suit) {
|
||||
Assertions.assertTrue(suit.cakeOffsetSel0() > 0);
|
||||
Assertions.assertFalse(suit.cakeOffsetSel0() < 0);
|
||||
Assertions.assertTrue(suit.cakeOffsetBank() > 0);
|
||||
Assertions.assertFalse(suit.cakeOffsetBank() < 0);
|
||||
Assertions.assertNotEquals(BigInteger.ZERO, suit.maxWaterLevel());
|
||||
Assertions.assertNotEquals(BigInteger.ONE, suit.maxWaterLevel());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2014, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.x4o.fc18.zion7.flame4;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests four corner number taste logic.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Se[ 5, 2025
|
||||
*/
|
||||
public class FCFlameNumberTasteTest {
|
||||
|
||||
@Test
|
||||
public void testChocoSign() throws Exception {
|
||||
FCFlameNumberTaste taste = FCFlameNumberTaste.NUMBER_POSITIVE;
|
||||
Assertions.assertTrue(taste.statusSignPositive());
|
||||
Assertions.assertFalse(taste.statusSignNegative());
|
||||
|
||||
taste = FCFlameNumberTaste.INFINITY_NEGATIVE_CARRY;
|
||||
Assertions.assertFalse(taste.statusSignPositive());
|
||||
Assertions.assertTrue(taste.statusSignNegative());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMeltCycle() throws Exception {
|
||||
FCFlameNumberTaste taste = FCFlameNumberTaste.NUMBER_POSITIVE;
|
||||
FCFlameNumberTaste tasteNew = taste.chocoRemeltDown();
|
||||
Assertions.assertEquals(taste, tasteNew);
|
||||
tasteNew = tasteNew.chocoRemeltUp();
|
||||
Assertions.assertEquals(FCFlameNumberTaste.NUMBER_POSITIVE_CARRY, tasteNew);
|
||||
tasteNew = tasteNew.chocoRemeltUp();
|
||||
Assertions.assertEquals(FCFlameNumberTaste.INFINITY_POSITIVE, tasteNew);
|
||||
tasteNew = tasteNew.chocoRemeltUp();
|
||||
Assertions.assertEquals(FCFlameNumberTaste.INFINITY_POSITIVE_CARRY, tasteNew);
|
||||
tasteNew = tasteNew.chocoRemeltUp();
|
||||
Assertions.assertEquals(FCFlameNumberTaste.FLAG_ROUNDED, tasteNew);
|
||||
tasteNew = tasteNew.chocoRemeltUp();
|
||||
Assertions.assertEquals(FCFlameNumberTaste.FLAG_NAN, tasteNew);
|
||||
tasteNew = tasteNew.chocoRemeltUp();
|
||||
Assertions.assertEquals(FCFlameNumberTaste.FLAG_NAN, tasteNew);
|
||||
tasteNew = tasteNew.chocoRemeltUp();
|
||||
Assertions.assertEquals(FCFlameNumberTaste.FLAG_NAN, tasteNew);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue