Skip to content

Commit

Permalink
18208: Adds null option to set_digits to skip setting the digit (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
howsohazard authored Nov 7, 2023
1 parent 450179f commit 85309ba
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)))"
},

Expand Down
1 change: 1 addition & 0 deletions src/Amalgam/amlg_code/full_test.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
16 changes: 16 additions & 0 deletions src/Amalgam/interpreter/InterpreterOpcodesMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
19 changes: 10 additions & 9 deletions src/Amalgam/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3535,7 +3536,7 @@ deep sets

--set_entity_root_permission--
RootTest
1699368539.937534
1699373993.645802
(true)

RootTest
Expand Down Expand Up @@ -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
Expand All @@ -3778,7 +3779,7 @@ hello
)
)
)
"e� �3��B?��'0��"
"��&��a���lQR��"
)
(set_entity_rand_seed
(first
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -4758,4 +4759,4 @@ Expecting 1000: 1000
concurrent entity writes successful: (true)

--total execution time--
1.6134569644927979
1.0938808917999268

0 comments on commit 85309ba

Please sign in to comment.