FC18: Made NCR signed and added Dozeger 192 bit integer support
This commit is contained in:
parent
4c2fbcfe2b
commit
d41af20079
10 changed files with 241 additions and 33 deletions
|
|
@ -139,30 +139,50 @@ final public class FourCornerRecipe {
|
|||
}
|
||||
|
||||
static public List<Integer> toDecimalsX06(int value) {
|
||||
return toDecimalsX00(new ArrayList<>(), value, true);
|
||||
return toDecimalsX00(new ArrayList<>(), Integer.toString(value), true);
|
||||
}
|
||||
|
||||
static public List<Integer> toDecimalsX18(int value) {
|
||||
return toDecimalsX00(new ArrayList<>(), value, false);
|
||||
return toDecimalsX00(new ArrayList<>(), Integer.toString(value), false);
|
||||
}
|
||||
|
||||
static public void toDecimalsX06(List<Integer> out, int value) {
|
||||
toDecimalsX00(out, value, true);
|
||||
toDecimalsX00(out, Integer.toString(value), true);
|
||||
}
|
||||
|
||||
static public void toDecimalsX18(List<Integer> out, int value) {
|
||||
toDecimalsX00(out, value, false);
|
||||
toDecimalsX00(out, Integer.toString(value), false);
|
||||
}
|
||||
|
||||
static private List<Integer> toDecimalsX00(List<Integer> out, int value, boolean isSixBit) {
|
||||
String valueStr = Integer.toString(value);
|
||||
PrimitiveIterator.OfInt i = valueStr.codePoints().iterator();
|
||||
static public List<Integer> toDecimalsX06(BigInteger value) {
|
||||
return toDecimalsX00(new ArrayList<>(), value.toString(10), true);
|
||||
}
|
||||
|
||||
static public List<Integer> toDecimalsX18(BigInteger value) {
|
||||
return toDecimalsX00(new ArrayList<>(), value.toString(10), false);
|
||||
}
|
||||
|
||||
static public void toDecimalsX06(List<Integer> out, BigInteger value) {
|
||||
toDecimalsX00(out, value.toString(10), true);
|
||||
}
|
||||
|
||||
static public void toDecimalsX18(List<Integer> out, BigInteger value) {
|
||||
toDecimalsX00(out, value.toString(10), false);
|
||||
}
|
||||
|
||||
static private List<Integer> toDecimalsX00(List<Integer> out, String value, boolean isSixBit) {
|
||||
boolean negative = value.startsWith("-");
|
||||
String valueClean = value.replaceAll("-", "");
|
||||
PrimitiveIterator.OfInt i = valueClean.codePoints().iterator();
|
||||
boolean first = true;
|
||||
while (i.hasNext()) {
|
||||
int chr = i.nextInt();
|
||||
int num = chr - '0';
|
||||
if (first) {
|
||||
first = false; // Add escaping only once for six bit mode
|
||||
if (negative) {
|
||||
out.add(FCDotCDC1604DashP6.NY19_MINUS.ordinal());
|
||||
}
|
||||
if (isSixBit) {
|
||||
out.addAll(FCDotPIE9CDash10.valueOf(num).baklavaPointSequence());
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
package org.x4o.fc18;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -251,6 +252,30 @@ public class FourCornerUnicodeDisplay {
|
|||
renderFromInt18(math, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void strobeNumberDozeger(BigInteger value) {
|
||||
List<Integer> numberCandy = new ArrayList<>();
|
||||
FourCornerRecipe.toDecimalsX18(numberCandy, value);
|
||||
renderFromInt18(numberCandy, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void strobeNumberDozimal(BigDecimal value) {
|
||||
List<Integer> numberCandy = new ArrayList<>();
|
||||
FourCornerRecipe.toDecimalsX18(numberCandy, value.unscaledValue());
|
||||
numberCandy.add(FCDotCDC1604DashP6.NY18_ASTERISK.ordinal());
|
||||
numberCandy.add(FCDotCDC1604DashP6.NX16_P.ordinal());
|
||||
numberCandy.add(FCDotCDC1604DashP6.NX15_O.ordinal());
|
||||
numberCandy.add(FCDotCDC1604DashP6.NX23_W.ordinal());
|
||||
numberCandy.add(FCDotCDC1604DashP6.NY25_ROUND_LEFT.ordinal());
|
||||
numberCandy.add(FCDotCDC1604DashP6.NY18_ASTERISK.ordinal());
|
||||
FourCornerRecipe.toDecimalsX18(numberCandy, 1);
|
||||
FourCornerRecipe.toDecimalsX18(numberCandy, 0);
|
||||
FourCornerRecipe.toDecimalsX18(numberCandy, value.scale());
|
||||
numberCandy.add(FCDotCDC1604DashP6.NY24_ROUND_RIGHT.ordinal());
|
||||
renderFromInt18(numberCandy, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void strobeNCR1632(BigInteger numerator, BigInteger denominator) {
|
||||
List<Integer> math = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
package org.x4o.fc18.zion7;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -41,8 +42,12 @@ public interface FourCornerZion7Candlelier extends FourCornerZion7AlphaOmega {
|
|||
|
||||
/// Block of one of more number grams of given base.
|
||||
void strobeNumberGrams(FourCornerZion7NumberGram gram, List<Integer> values);
|
||||
//void strobeNumberDozimal(BigDecimal value);
|
||||
//void strobeNumberDozeger(BigInteger value); // up to 192 bit integer
|
||||
|
||||
/// Embed signed integer up to 192 bit
|
||||
void strobeNumberDozeger(BigInteger value);
|
||||
|
||||
/// Embed signed decimal up to 192 bit
|
||||
void strobeNumberDozimal(BigDecimal value);
|
||||
|
||||
/// 1152 bit fractions of two 576 bit numbers.
|
||||
void strobeNCR1632(BigInteger numerator, BigInteger denominator);
|
||||
|
|
@ -70,6 +75,14 @@ public interface FourCornerZion7Candlelier extends FourCornerZion7AlphaOmega {
|
|||
default void strobeNumberGrams(FourCornerZion7NumberGram gram, List<Integer> values) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void strobeNumberDozeger(BigInteger value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void strobeNumberDozimal(BigDecimal value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void strobeNCR1632(BigInteger numerator, BigInteger denominator) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,11 @@ import java.util.List;
|
|||
/// @version 1.0 Aug 24, 2025
|
||||
public final class FourCornerZion7Petroglyphs {
|
||||
|
||||
public static final BigInteger DOZEGER192_MASK_PAGE = BigInteger.valueOf(0b111);
|
||||
public static final BigInteger DOZEGER192_VALUE_MAX = new BigInteger("7FFFFFFFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFFFFFFFF", 16);
|
||||
|
||||
public static final BigInteger NCR1632_MASK_PAGE = BigInteger.valueOf(0x1FF);
|
||||
public static final BigInteger NCR1632_VALUE_MAX = new BigInteger("FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16);
|
||||
public static final BigInteger NCR1632_VALUE_MAX = new BigInteger("7FFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16);
|
||||
public static final List<Integer> SAND_WORM_SIGN = List.of(24,48,72,96,120,144,168,192);
|
||||
|
||||
private FourCornerZion7Petroglyphs() {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ package org.x4o.fc18.zion7;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
|
@ -143,7 +144,7 @@ public class FourCornerZionStenoGrapher {
|
|||
Objects.requireNonNull(gram);
|
||||
Objects.requireNonNull(values);
|
||||
if (isSixBit) {
|
||||
// todo
|
||||
// TODO
|
||||
}
|
||||
int gramCount = values.size();
|
||||
for (int i = 0; i < gramCount; i++) {
|
||||
|
|
@ -154,11 +155,42 @@ public class FourCornerZionStenoGrapher {
|
|||
if (gramValue > gram.cutCount()) {
|
||||
throw new IllegalArgumentException("Gram value is greater than cut count: " + gram.cutCount());
|
||||
}
|
||||
strobeWord(gram.cutZeroCakePoint() + gramValue);
|
||||
outAdd(gram.cutZeroCakePoint() + gramValue);
|
||||
}
|
||||
outFlush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void strobeNumberDozeger(BigInteger value) {
|
||||
Objects.requireNonNull(value);
|
||||
if (value.compareTo(FourCornerZion7Petroglyphs.DOZEGER192_VALUE_MAX) > 0) {
|
||||
throw new IllegalArgumentException("Value dozeger is larger than 192 bit: " + value);
|
||||
}
|
||||
BigInteger valuePos = value;
|
||||
boolean negative = false;
|
||||
if (value.signum() == -1) {
|
||||
valuePos = value.negate();
|
||||
negative = true;
|
||||
}
|
||||
for (int i = 63; i >= 0; i--) {
|
||||
int bankValue = valuePos.shiftRight(i * 3).and(FourCornerZion7Petroglyphs.DOZEGER192_MASK_PAGE).intValue();
|
||||
if (i == 63 && negative) {
|
||||
bankValue = (bankValue & 0b011) + 4;
|
||||
}
|
||||
if (bankValue == 0 && i > 0) {
|
||||
continue;
|
||||
}
|
||||
int cakePoint = FourCornerDotCake.FC_DOZEGER_192.getStart() + bankValue + (i * 8);
|
||||
outAdd(cakePoint);
|
||||
}
|
||||
outFlush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void strobeNumberDozimal(BigDecimal value) {
|
||||
Objects.requireNonNull(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void strobeNCR1632(BigInteger numerator, BigInteger denominator) {
|
||||
Objects.requireNonNull(numerator);
|
||||
|
|
@ -166,20 +198,31 @@ public class FourCornerZionStenoGrapher {
|
|||
if (denominator.equals(BigInteger.ZERO)) { // 0/1 = zero but 1/0 is NaN
|
||||
throw new IllegalArgumentException("The denominator value ZERO is not allowed.");
|
||||
}
|
||||
//if (denominator.signum() == -1) {
|
||||
// // TODO: check if we need one octal for pos/neg/qNaN/sNaN/pos_inf/neg_inf/free/free options
|
||||
//}
|
||||
if (numerator.compareTo(FourCornerZion7Petroglyphs.NCR1632_VALUE_MAX) > 0) {
|
||||
throw new IllegalArgumentException("Value numerator is larger than 576 bit: " + numerator);
|
||||
}
|
||||
if (denominator.compareTo(FourCornerZion7Petroglyphs.NCR1632_VALUE_MAX) > 0) {
|
||||
throw new IllegalArgumentException("Value denominator is larger than 576 bit: " + denominator);
|
||||
}
|
||||
|
||||
BigInteger numeratorPos = numerator;
|
||||
boolean numeratorNegative = false;
|
||||
if (numerator.signum() == -1) {
|
||||
numeratorPos = numerator.negate();
|
||||
numeratorNegative = true;
|
||||
}
|
||||
BigInteger denominatorPos = denominator;
|
||||
boolean denominatorNegative = false;
|
||||
if (denominator.signum() == -1) {
|
||||
denominatorPos = denominator.negate();
|
||||
denominatorNegative = true;
|
||||
}
|
||||
if (isSixBit) {
|
||||
outAddAll(FCDotDEC2701DashPX0.ESC68_NCR.baklavaPointSequence());
|
||||
for (int i = 63; i >= 0; i--) {
|
||||
int bankValue = numerator.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
|
||||
int bankValue = numeratorPos.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
|
||||
if (i == 63 && numeratorNegative) {
|
||||
bankValue = (bankValue & 0b011) + 4;
|
||||
}
|
||||
if (bankValue == 0 && i > 0) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -208,7 +251,10 @@ public class FourCornerZionStenoGrapher {
|
|||
outAdd(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueLSB);
|
||||
}
|
||||
for (int i = 63; i >= 0; i--) {
|
||||
int bankValue = denominator.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
|
||||
int bankValue = denominatorPos.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
|
||||
if (i == 63 && denominatorNegative) {
|
||||
bankValue = (bankValue & 0b011) + 4;
|
||||
}
|
||||
if (bankValue == 0 && i > 0) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -241,7 +287,10 @@ public class FourCornerZionStenoGrapher {
|
|||
return;
|
||||
}
|
||||
for (int i = 63; i >= 0; i--) {
|
||||
int bankValue = numerator.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
|
||||
int bankValue = numeratorPos.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
|
||||
if (i == 63 && numeratorNegative) {
|
||||
bankValue = (bankValue & 0b011) + 4;
|
||||
}
|
||||
if (bankValue == 0 && i > 0) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -249,7 +298,10 @@ public class FourCornerZionStenoGrapher {
|
|||
outAdd(cakePoint);
|
||||
}
|
||||
for (int i = 63; i >= 0; i--) {
|
||||
int bankValue = denominator.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
|
||||
int bankValue = denominatorPos.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
|
||||
if (i == 63 && denominatorNegative) {
|
||||
bankValue = (bankValue & 0b011) + 4;
|
||||
}
|
||||
if (bankValue == 0 && i > 0) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,12 @@ public class FourCornerZionStenoLexer {
|
|||
if (FourCornerDotCake.FC_SANDWORM_15.equals(cakeSlice)) {
|
||||
continue; // parse nether body manually
|
||||
}
|
||||
if (FourCornerDotCake.FC_DOZEGER_192.equals(cakeSlice)) {
|
||||
continue; // parse block manually
|
||||
}
|
||||
if (FourCornerDotCake.FC_DOZIMAL_192.equals(cakeSlice)) {
|
||||
continue; // parse block manually
|
||||
}
|
||||
if (FourCornerDotCake.FC_NCR1632_DEN.equals(cakeSlice)) {
|
||||
continue; // parse block manually
|
||||
}
|
||||
|
|
@ -100,6 +106,7 @@ public class FourCornerZionStenoLexer {
|
|||
CAKE_SLICE_EATERS.add(new StenoScannerWordCakeSlice(cakeSlice));
|
||||
}
|
||||
CAKE_SLICE_EATERS.add(new StenoScannerCDCDEC());
|
||||
CAKE_SLICE_EATERS.add(new StenoScannerDozeger());
|
||||
CAKE_SLICE_EATERS.add(new StenoScannerNCR18());
|
||||
CAKE_SLICE_EATERS.add(new StenoScannerSandWorm());
|
||||
ArrayList.class.cast(CAKE_SLICE_EATERS).trimToSize();
|
||||
|
|
@ -194,12 +201,28 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
|
||||
private void ncrBankFire() {
|
||||
boolean numeratorNegetive = false;
|
||||
boolean denominatorNegetive = false;
|
||||
BigInteger numerator = BigInteger.ZERO;
|
||||
BigInteger denominator = BigInteger.ZERO;
|
||||
for (int i = 0; i < numeratorBank.length; i++) {
|
||||
if (i == 63 && (numeratorBank[i] & 0b100) == 4) {
|
||||
numeratorNegetive = true;
|
||||
numeratorBank[i] = numeratorBank[i] & 0b011;
|
||||
}
|
||||
if (i == 63 && (denominatorBank[i] & 0b100) == 4) {
|
||||
denominatorNegetive = true;
|
||||
denominatorBank[i] = denominatorBank[i] & 0b011;
|
||||
}
|
||||
numerator = numerator.add(BigInteger.valueOf(numeratorBank[i]).shiftLeft(i * 9));
|
||||
denominator = denominator.add(BigInteger.valueOf(denominatorBank[i]).shiftLeft(i * 9));
|
||||
}
|
||||
if (numeratorNegetive) {
|
||||
numerator = numerator.negate();
|
||||
}
|
||||
if (denominatorNegetive) {
|
||||
denominator = denominator.negate();
|
||||
}
|
||||
handler.strobeNCR1632(numerator, denominator);
|
||||
// reset the bank after each fire
|
||||
for (int i = 0; i < numeratorBank.length; i++) {
|
||||
|
|
@ -352,6 +375,52 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
}
|
||||
|
||||
static class StenoScannerDozeger extends StenoScanner {
|
||||
|
||||
static private final int CAKEPOINT_BANK0_END = FourCornerDotCake.FC_DOZEGER_192.getStart() + 8;
|
||||
|
||||
public StenoScannerDozeger() {
|
||||
super(FourCornerDotCake.FC_DOZEGER_192);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) {
|
||||
int valueBank[] = new int[64];
|
||||
boolean negetive = false;
|
||||
boolean missingSparkler = true;
|
||||
for (int i = idxFirst; i <= idxLast; i++) {
|
||||
int cakePoint = lexer.input.get(i);
|
||||
int valueOffset = cakePoint - FourCornerDotCake.FC_DOZEGER_192.getStart();
|
||||
int bankSelect = valueOffset / 8;
|
||||
int bankValue = valueOffset % 8;
|
||||
if (bankSelect == 63 && (bankValue & 0b100) == 4) {
|
||||
negetive = true;
|
||||
bankValue = bankValue & 0b011; // remove sign bit from value
|
||||
}
|
||||
valueBank[bankSelect] = bankValue;
|
||||
if (cakePoint > CAKEPOINT_BANK0_END) {
|
||||
missingSparkler = true;
|
||||
continue; // Only fire value on lowest value select
|
||||
}
|
||||
BigInteger valueNumber = BigInteger.ZERO;
|
||||
for (int ii = 0; ii < valueBank.length; ii++) {
|
||||
valueNumber = valueNumber.add(BigInteger.valueOf(valueBank[ii]).shiftLeft(ii * 3));
|
||||
}
|
||||
if (negetive) {
|
||||
valueNumber = valueNumber.negate();
|
||||
}
|
||||
lexer.handler.strobeNumberDozeger(valueNumber);
|
||||
for (int ii = 0; ii < valueBank.length; ii++) {
|
||||
valueBank[ii] = 0;
|
||||
}
|
||||
missingSparkler = false;
|
||||
}
|
||||
if (missingSparkler) {
|
||||
lexer.smokeSignals.burnNumberDozegerMissingSparkler(lexer.currLine, lexer.currCol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class StenoScannerNCR18 extends StenoScanner {
|
||||
|
||||
static private final int CAKEPOINT_BANK0_END = FourCornerDotCake.FC_NCR1632_DEN.getStart() + 512;
|
||||
|
|
@ -382,7 +451,7 @@ public class FourCornerZionStenoLexer {
|
|||
missingSparkler = false;
|
||||
}
|
||||
if (missingSparkler) {
|
||||
lexer.smokeSignals.burnNCR1632MissingBankSparkler(lexer.currLine, lexer.currCol);
|
||||
lexer.smokeSignals.burnNCR1632MissingSparkler(lexer.currLine, lexer.currCol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,8 +42,9 @@ public interface FourCornerZionStenoLexerSmoke {
|
|||
|
||||
void burnSandWalkerStepUnaligned(int line, int col, int size);
|
||||
|
||||
void burnNumberDozegerMissingSparkler(int line, int col);
|
||||
|
||||
void burnNCR1632MissingBankSparkler(int line, int col);
|
||||
void burnNCR1632MissingSparkler(int line, int col);
|
||||
|
||||
interface Adapter extends FourCornerZionStenoLexerSmoke {
|
||||
|
||||
|
|
@ -72,7 +73,11 @@ public interface FourCornerZionStenoLexerSmoke {
|
|||
}
|
||||
|
||||
@Override
|
||||
default void burnNCR1632MissingBankSparkler(int line, int col) {
|
||||
default void burnNumberDozegerMissingSparkler(int line, int col) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void burnNCR1632MissingSparkler(int line, int col) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -111,8 +116,13 @@ public interface FourCornerZionStenoLexerSmoke {
|
|||
}
|
||||
|
||||
@Override
|
||||
default void burnNCR1632MissingBankSparkler(int line, int col) {
|
||||
burnMonoPipe(line, col, "burnNCR1632MissingBankSparkler");
|
||||
default void burnNumberDozegerMissingSparkler(int line, int col) {
|
||||
burnMonoPipe(line, col, "burnNumberDozegerMissingSparkler");
|
||||
}
|
||||
|
||||
@Override
|
||||
default void burnNCR1632MissingSparkler(int line, int col) {
|
||||
burnMonoPipe(line, col, "burnNCR1632MissingSparkler");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue