Support Arithmetic Operations#277
Conversation
|
It is one way to do that. Since we are going to support arithmetic operation, why do not we try to support it more naturally? How about this use case set x = 10
set x=10
set y = x * 2 + 10
set y=x*2 + 10Lets commit into supporting it, but limit the supported operators to the one you mentioned. Also be careful with invalid operation like dividing by zero. |
|
I was thinking of something like this. However, I wanted to use the existing |
b811226 to
037bd51
Compare
|
@aaumar25 the more natural way has been implemented. It can now be used with and without adding space. |
395d144 to
7070296
Compare
821c4a4 to
86fdbbd
Compare
|
@aaumar25 Should the PR title be marked as breaking?
And additionally, adding information to the PR description.
|
aaumar25
left a comment
There was a problem hiding this comment.
Good approach regarding the calculation structure. I think the output of calc should be floating point instead of integer. What happen if want the following operation to change next carrier target position with car_pos + 0.33?
I do not think it is breaking anything, it just added one field with default value, so existing parameters does not need to explicitly assign However, I am thinking about catching the |
|
Just squash and merge |
Fix: #276
The
set()function has been extended to support arithmetic operations.The existing behavior remains unchanged to preserve backward compatibility
Previously:set (variable) (value)New:
set (variable) (value) [operation] [value]valueis computed when the=symbol is used. Variables with numeric values can be used. Numbers, variables, and operators may be separated with spaces.For example,
set x =10*2+1is equivalent toset x = 10 * 2 + 1.Supported operators and symbols: +, -, *, /, %, (, )
Example:
set x 10set y x + 5 // y = 15set z y * x // z = 150When
=is used, variables are resolved.