mirror of
https://github.com/zeroflag/fcl.git
synced 2025-01-11 20:01:10 +01:00
binary literals
This commit is contained in:
parent
214704f1ef
commit
b454b6f32f
2 changed files with 9 additions and 0 deletions
|
@ -32,6 +32,8 @@ public class Num implements Obj, LogicOperand, ArithmeticOperand {
|
||||||
try {
|
try {
|
||||||
if (str.startsWith("0x"))
|
if (str.startsWith("0x"))
|
||||||
return new Num(Long.parseLong(str.substring(2), 16));
|
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));
|
return new Num(Long.parseLong(str));
|
||||||
} catch (NumberFormatException e1) {
|
} catch (NumberFormatException e1) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -91,7 +91,14 @@ public class FclTest {
|
||||||
assertEquals(asList(1l, 85l), evalGetStack("2 8 pow 3 /mod"));
|
assertEquals(asList(1l, 85l), evalGetStack("2 8 pow 3 /mod"));
|
||||||
assertEquals(3, evalPop("10 3 /mod nip").intValue());
|
assertEquals(3, evalPop("10 3 /mod nip").intValue());
|
||||||
assertEquals(1, evalPop("10 3 /mod drop").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
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue