thank you Little John
one of my dreams is to have PB pre-processor that would simulate operator and function overloading, you could then use a big-math library using normal syntax.
Evaluate and process math expressions
-
- Addict
- Posts: 4519
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Evaluate and process math expressions
I mainly made the following changes to the pre-processor in the 2nd post:
- New: Functions "Ceil()", "Trunc()", and "Floor()" can be replaced with the equivalent PB functions.
More functions can be added easily. - New: Any boolean expression can be enclosed in a "Bool()" function.
- Flags are used for controlling what the module will replace.
Re: Evaluate and process math expressions
Thanks for the updates Little John! Really nice to see someone bettering in this area.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: Evaluate and process math expressions
Question:
-9^0.5 is equal to pow(-9,0.5) and this is not defined.
PB use this priority levels
imo ^ should be lower than 8 and higher than 5 (in my code i use "7.5").
The first - is not prio 4, it is prio 8 - it is a sign.
in my opinion this should fail!check("-9^0.5", "-3")
-9^0.5 is equal to pow(-9,0.5) and this is not defined.
PB use this priority levels
Code: Select all
Priority Level | Operators
---------------+---------------------
8 (high) | ~, -
7 | <<, >>, %, !
6 | |, &
5 | *, /
4 | +, -
3 | >, >=, <, <=, =, <>
2 | Not
1 (low) | And, Or, XOr
The first - is not prio 4, it is prio 8 - it is a sign.
-
- Addict
- Posts: 4519
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Evaluate and process math expressions
Hi,GPI wrote:Question:
in my opinion this should fail!check("-9^0.5", "-3")
-9^0.5 is equal to pow(-9,0.5) and this is not defined.
it works as intended. My parser works according to the well established math rules:
Code: Select all
-9^0.5 = - (9^0.5) = -3
(-9)^0.5 = undefined (if we only work with real numbers)
Re: Evaluate and process math expressions
ok, thanks, than ^ must have a prio over 8...
edit:
nope, it should be 7.5... the first - is always special...
edit:
nope, it should be 7.5... the first - is always special...
Last edited by GPI on Tue Sep 22, 2015 9:24 pm, edited 1 time in total.
-
- Addict
- Posts: 4519
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Evaluate and process math expressions
Thank you, davido!
You are very welcome.
You are very welcome.
Re: Evaluate and process math expressions
^ would be above -, so that would make it >8 .GPI wrote:ok, thanks, than ^ must have a prio over 8...
edit:
nope, it should be 7.5... the first - is always special...
In mathematical operator precedence the unary operator - can be considered equal with the multiplication operator * .
This is evidence by writing things in this format: -1(x) = -x .
Since ^ has a higher priority than *, this would mean it also has a higher priority than - .
This in turn leads to the natural conclusion that -9^2 = -81, because it is the same as -1(9)^2 .