binary literals

This commit is contained in:
zeroflag 2021-07-10 20:38:36 +02:00
parent 214704f1ef
commit b454b6f32f
2 changed files with 9 additions and 0 deletions

View file

@ -32,6 +32,8 @@ public class Num implements Obj, LogicOperand, ArithmeticOperand {
try {
if (str.startsWith("0x"))
return new Num(Long.parseLong(str.substring(2), 16));
else if (str.startsWith("0b"))
return new Num(Long.parseLong(str.substring(2), 2));
return new Num(Long.parseLong(str));
} catch (NumberFormatException e1) {
try {

View file

@ -91,7 +91,14 @@ public class FclTest {
assertEquals(asList(1l, 85l), evalGetStack("2 8 pow 3 /mod"));
assertEquals(3, evalPop("10 3 /mod nip").intValue());
assertEquals(1, evalPop("10 3 /mod drop").intValue());
}
@Test
public void testNumberLiterals() {
assertEquals(12345, evalPop("12345").longValue());
assertEquals(255, evalPop("0xFF").longValue());
assertEquals(131, evalPop("0b10000011").longValue());
assertEquals(-1.44, evalPop("-1.44").doubleValue(), 0.01);
}
@Test