Skip to content

Commit 7dc3784

Browse files
authored
Merge pull request #25 from PetrPytelka/clng_cdbl
New functions CLng and CDbl
2 parents 065626f + 868cc20 commit 7dc3784

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/main/java/com/scriptbasic/utility/functions/UtilityFunctions.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
import com.scriptbasic.classification.Constant;
55
import com.scriptbasic.classification.System;
66
import com.scriptbasic.classification.Utility;
7+
import com.scriptbasic.executors.rightvalues.BasicDoubleValue;
8+
import com.scriptbasic.executors.rightvalues.BasicLongValue;
79
import com.scriptbasic.interfaces.BasicRuntimeException;
810
import com.scriptbasic.log.Logger;
911
import com.scriptbasic.log.LoggerFactory;
1012
import com.scriptbasic.spi.BasicArray;
1113
import com.scriptbasic.spi.Interpreter;
1214
import com.scriptbasic.utility.MagicBean;
1315
import com.scriptbasic.utility.NoInstance;
16+
import com.scriptbasic.utility.RightValueUtility;
1417

1518
import java.lang.reflect.Array;
1619
import java.nio.charset.StandardCharsets;
@@ -143,4 +146,19 @@ public static Long length(final Object arg) {
143146
return null;
144147
}
145148

149+
@BasicFunction(classification = Utility.class)
150+
public static Double cdbl(final Object arg) throws BasicRuntimeException {
151+
if (arg == null) {
152+
throw new BasicRuntimeException("undef cannot be converted to double");
153+
}
154+
return BasicDoubleValue.asDouble(RightValueUtility.createRightValue(arg));
155+
}
156+
157+
@BasicFunction(classification = Utility.class)
158+
static public Long clng(final Object arg) throws BasicRuntimeException {
159+
if (arg == null) {
160+
throw new BasicRuntimeException("undef cannot be converted to long");
161+
}
162+
return BasicLongValue.asLong(RightValueUtility.createRightValue(arg));
163+
}
146164
}

src/test/java/com/scriptbasic/testprograms/TestPrograms.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ public void testStringFunctions() throws Exception {
168168
codeTest("TestStringFunctions.bas", "0189123");
169169
}
170170

171+
@Test
172+
public void testUtilityFunctions() throws Exception {
173+
codeTest("TestUtilityFunctions.bas", "DONE");
174+
}
175+
171176
@Test
172177
public void testJavaObjectFieldAccess() throws ScriptBasicException, ClassNotFoundException, AnalysisException {
173178
final var e = new TestingExecutor();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
' test function cdbl
2+
assert("cdbl_1", cdbl(2)=2.0)
3+
assert("cdbl_2", cdbl(2.5)=2.5)
4+
assert("cdbl_3", cdbl("2")=2.0)
5+
assert("cdbl_4", cdbl("2.5")=2.5)
6+
7+
' test function clng
8+
assert("clng_1", clng(2)=2)
9+
assert("clng_2", clng("2")=2)
10+
assert("clng_3", clng(true)=1)
11+
12+
print "DONE"

0 commit comments

Comments
 (0)