diff --git a/SMILEBASIC/TEST.txt b/SMILEBASIC/TEST.txt index 61e4ac3..b88087c 100644 --- a/SMILEBASIC/TEST.txt +++ b/SMILEBASIC/TEST.txt @@ -22,6 +22,13 @@ ASSERT__ ROUND(-1)==-1, "ROUND" ASSERT__ ROUND(-1.25)==-1, "ROUND" ASSERT__ ROUND(-1.5)==-2, "ROUND" +ASSERT__ VAL("0")==0, "VAL" +ASSERT__ VAL("1")==1, "VAL" +ASSERT__ VAL("-1")==-1, "VAL" +ASSERT__ VAL("&HA")==10, "VAL" +ASSERT__ VAL("&H-A")==0, "VAL" +ASSERT__ VAL("&B10")==2, "VAL" +ASSERT__ VAL("aa")==0, "VAL" ASSERT__ SUBST$("0123456789",0,"B")=="B","SUBST$" ASSERT__ SUBST$("0123456789",0,4,"B")=="B456789","SUBST$" ASSERT__ SUBST$("",0,4,"B")=="B","SUBST$" diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 3fe71ee..aed34c6 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -226,10 +226,14 @@ class BuiltinFunction { try { - if(str[0..2] == "&H") + if(str.length > 2 && str[0..2] == "&H") { return str[2..$].to!int(16); } + if(str.length > 2 && str[0..2] == "&B") + { + return str[2..$].to!int(2); + } double val = str.to!double; return val; }