diff --git a/docs/language.js b/docs/language.js index 249efb5e..a3e5a370 100644 --- a/docs/language.js +++ b/docs/language.js @@ -192,10 +192,10 @@ var data = [ }, { - "parameter" : "set_digits number value [number base] [list of number digits] [number start_digit] [number end_digit] [bool relative_to_zero]", + "parameter" : "set_digits number value [number base] [list of number or null digits] [number start_digit] [number end_digit] [bool relative_to_zero]", "output" : "number", "new value" : "new", - "description" : "Evaluates to a number having each of the values in the list of digits replace each of the relative digits in value for the given base. If base is omitted, 10 is the default. The parameters start_digit and end_digit can be used to get a specific set of digits, but can also be infinite or null to catch all the digits on one side of the number. The interpretation of start_digit and end_digit are with respect to relative_to_zero, which defaults to true. If relative_to_zero is true, then the digits are indexed from their distance to zero, such as \"5 4 3 2 1 0 . -1 -2\". If relative_to_zero is false, then the digits are indexed from their most significant digit, such as \"0 1 2 3 4 5 . 6 7\". The default values of start_digit and end_digit are the most and least significant digits respectively.", + "description" : "Evaluates to a number having each of the values in the list of digits replace each of the relative digits in value for the given base. If a digit is null in digits, then that digit is not set. If base is omitted, 10 is the default. The parameters start_digit and end_digit can be used to get a specific set of digits, but can also be infinite or null to catch all the digits on one side of the number. The interpretation of start_digit and end_digit are with respect to relative_to_zero, which defaults to true. If relative_to_zero is true, then the digits are indexed from their distance to zero, such as \"5 4 3 2 1 0 . -1 -2\". If relative_to_zero is false, then the digits are indexed from their most significant digit, such as \"0 1 2 3 4 5 . 6 7\". The default values of start_digit and end_digit are the most and least significant digits respectively.", "example" : "(print (set_digits 16 8 (list 1 1)))\n(print (get_digits (set_digits 1234567.8 10 (list 1 0 1 0) 2 5 (false)) 10 2 5 (false)))" }, diff --git a/src/Amalgam/amlg_code/full_test.amlg b/src/Amalgam/amlg_code/full_test.amlg index ace84eea..ebd10677 100644 --- a/src/Amalgam/amlg_code/full_test.amlg +++ b/src/Amalgam/amlg_code/full_test.amlg @@ -251,6 +251,7 @@ (print (set_digits 1234567.8 10 (list 5 5 5 5 5) 4 8 (false)) "\n") (print (set_digits 1.2345678e100 10 (list 5 5 5 5 5) 0 4 (false)) "\n") (print (set_digits 1.2345678e100 10 (list 5 5 5 5 5) 4 8 (false)) "\n") + (print (set_digits 1.2345678e100 10 (list 5 (null) 5 (null) 5) 4 8 (false)) "\n") ;these should all print (list 1 0 1) (print (get_digits (set_digits 1234567.8 10 (list 1 0 1 0) 2 5 (false)) 10 2 5 (false))) diff --git a/src/Amalgam/interpreter/InterpreterOpcodesMath.cpp b/src/Amalgam/interpreter/InterpreterOpcodesMath.cpp index e343e91a..656ff377 100644 --- a/src/Amalgam/interpreter/InterpreterOpcodesMath.cpp +++ b/src/Amalgam/interpreter/InterpreterOpcodesMath.cpp @@ -380,6 +380,14 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_SET_DIGITS(EvaluableNode * if(cur_digit_index >= digits_ocn.size()) break; + + //skip nulls + if(EvaluableNode::IsNull(digits_ocn[cur_digit_index])) + { + cur_digit_index++; + continue; + } + double new_digit = EvaluableNode::ToNumber(digits_ocn[cur_digit_index++]); result_value -= value_digit * place_value; @@ -405,6 +413,14 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_SET_DIGITS(EvaluableNode * { if(cur_digit_index >= digits_ocn.size()) break; + + //skip nulls + if(EvaluableNode::IsNull(digits_ocn[cur_digit_index])) + { + cur_digit_index++; + continue; + } + double new_digit = EvaluableNode::ToNumber(digits_ocn[cur_digit_index++]); result_value -= value_digit * place_value; diff --git a/src/Amalgam/out.txt b/src/Amalgam/out.txt index dcc89439..9ccaadc6 100644 --- a/src/Amalgam/out.txt +++ b/src/Amalgam/out.txt @@ -462,6 +462,7 @@ abcdef 1234555.55 5.555567800000001e+100 1.2345555499999999e+100 +1.23456585e+100 (list 1 0 1 0) (list 1 0 1 0) (list 1 0 1 0) @@ -1251,7 +1252,7 @@ current_index: 2 interpreter "C:\\Users\\Chris Hazard\\Desktop\\Howso_repos\\amalgam\\x64\\MT_Release_EXE\\Amalgam.exe" raaa 2 rwww 1 - start_time 1699368539.269825 + start_time 1699373993.19914 www 1 x 12 zz 10 @@ -1294,7 +1295,7 @@ current_index: 2 interpreter "C:\\Users\\Chris Hazard\\Desktop\\Howso_repos\\amalgam\\x64\\MT_Release_EXE\\Amalgam.exe" raaa 2 rwww 1 - start_time 1699368539.269825 + start_time 1699373993.19914 www 1 x 12 zz 10 @@ -1336,7 +1337,7 @@ current_index: 2 interpreter "C:\\Users\\Chris Hazard\\Desktop\\Howso_repos\\amalgam\\x64\\MT_Release_EXE\\Amalgam.exe" raaa 2 rwww 1 - start_time 1699368539.269825 + start_time 1699373993.19914 www 1 x 12 zz 10 @@ -1604,7 +1605,7 @@ e: - .inf 25: (assoc a 1) -current date-time in epoch: 2023-11-07-09.48.59.6796740 +current date-time in epoch: 2023-11-07-11.19.53.4519210 2020-06-07 00:22:59 1391230800 1391230800 @@ -3535,7 +3536,7 @@ deep sets --set_entity_root_permission-- RootTest -1699368539.937534 +1699373993.645802 (true) RootTest @@ -3765,7 +3766,7 @@ hello ) ) ) - (set_entity_rand_seed new_entity "JÂF˜3°“:0Ñ”-I´»ÿ") + (set_entity_rand_seed new_entity "Bô%mmpd0Ñ”-I´»ÿ") (set_entity_rand_seed (first (create_entities @@ -3778,7 +3779,7 @@ hello ) ) ) - "eõ û3̇B?€Ý'0¿ÿ" + "ýË&îýaˆ¯ÛlQRàÿ" ) (set_entity_rand_seed (first @@ -3814,7 +3815,7 @@ hello ) ) ) - (set_entity_rand_seed new_entity "JÂF˜3°“:0Ñ”-I´»ÿ") + (set_entity_rand_seed new_entity "Bô%mmpd0Ñ”-I´»ÿ") (set_entity_rand_seed (first (create_entities @@ -4758,4 +4759,4 @@ Expecting 1000: 1000 concurrent entity writes successful: (true) --total execution time-- -1.6134569644927979 +1.0938808917999268