From 6df9bc25f89ebc8e69c1df5409da73cd6c81248e Mon Sep 17 00:00:00 2001 From: otya128 Date: Sun, 23 Aug 2015 11:48:46 +0900 Subject: [PATCH] =?UTF-8?q?VAL=E3=81=A7=E4=BA=8C=E9=80=B2=E6=95=B0?= =?UTF-8?q?=E3=82=92=E6=89=B1=E3=81=88=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SMILEBASIC/TEST.txt | 7 +++++++ SMILEBASIC/builtinfunctions.d | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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; }