Page 1 of 1

Hello Pythagoras

Posted: Tue Jan 07, 2025 6:46 pm
by Gerral
Our work depends on values that are taken from probing... in this case the Pythagoras theorem.

#31509 = #31501- [ #31502 - SQRT[ [ #31502 ^ 2 ]-[ 19.0000 ^ 2 ]]]

When this runs I get an undefined variable error.

I deconstructed the formula to simplify it for the controller and still have an issue.

Here you see where there is a value in #31502
IMG_5036.jpg
When taking the square root of the of the sum of the square of the sides.
IMG_5037.jpg
I'm still getting the undefined variable error

I am missing what I'm doing wrong.

Thanks in advance for your help and opinions. Sorry the images show sideways.

Re: Hello Pythagoras

Posted: Tue Jan 07, 2025 10:49 pm
by cncsnw
It looks like the "^" operator (exponentiation) binds with higher precedence than the "#" operator (variable dereferencing).

As a result, "#2 ^ 2" evaluates as "#[2 ^ 2]" and returns the value of variable #4.

"#31502 ^ 2" tries to access variable #992376004, which is invalid.

To get around this, you have to write "[#31502] ^ 2" instead.

Re: Hello Pythagoras

Posted: Wed Jan 08, 2025 8:07 am
by Gerral
You're exactly right. Great catch.

How do I report this bug?

Thanks again!

Re: Hello Pythagoras

Posted: Wed Jan 08, 2025 10:26 am
by suntravel
Gerral wrote: Wed Jan 08, 2025 8:07 am You're exactly right. Great catch.

How do I report this bug?

Thanks again!
It is not a bug, it is a feature ;)

8.2.14 [ ] – Numerical Expression
The left bracket ‘[’ and right bracket ‘]’ are used to delimit a numerical expression. Numerical expressions can contain
floating-point numbers or user/system variables in combination with mathematical operators and functions. The left
parenthesis ‘(’ or bracket ‘[’ and right parenthesis ‘)’ or bracket ‘]’ can be used between the first left bracket and last
right bracket to force operator precedence or associatively. A bracketed numerical expression can be used anywhere
a number would be used. Comparison operators (‘eq’, ‘ne’, etc.) have built-in rounding specified by Parameter 144.
Without this rounding, ‘eq’ would usually return “false‘’ when comparing two numbers calculated in different ways.
Comparison operators and logical operators (‘!’, ‘&&’, ‘||’) return 1.0 for “true” and 0.0 for “false”.

Example:
G91 X [13/64] Z [1+3/8] ; Move the X axis 13/64 (0.2031) units and the Z axis 1 3/8 (1.375) units incrementally
X[ SQRT [ABS[SIN [#101] - COS [#102]]]] ; Move X as a function of #101 and #102

Uwe

Re: Hello Pythagoras

Posted: Wed Jan 08, 2025 10:45 am
by Gerral
I love features! So does Microsoft :lol:

Re: Hello Pythagoras

Posted: Wed Jan 08, 2025 12:07 pm
by cncsnw
I think a better feature would be to give the "#" operator higher precedence than the "^" operator, but that is just my opinion.

Re: Hello Pythagoras

Posted: Wed Jan 08, 2025 1:56 pm
by suntravel
cncsnw wrote: Wed Jan 08, 2025 12:07 pm I think a better feature would be to give the "#" operator higher precedence than the "^" operator, but that is just my opinion.
Yes, this would save some typing...

Uwe

Re: Hello Pythagoras

Posted: Fri Jan 10, 2025 6:10 pm
by Gerral
It would make it behave like other GCode interpreters as well as all other languages too.