Rounding error?

philmasterplus

Active member
Because the expression
Code:
7/10
yields 0, not 0.7, which is probably what you expected. In ASH (and most C-like languages), division between two integers destroy the fractional part. Whether a negative real number is rounded up or down on integer conversion is dependent on the language and compiler/interpreter used. However, in ASH, you can expect:
PHP:
print(12/7); //Displays "1"
print((-12)/7); //Displays "-1"
Incidentally, ASH seems to have trouble interpreting negative numbers. That's why I wrapped -12 with parentheses.
 

Banana Lord

Member
Oh OK. I'm relatively new (and completely untrained) to all this "scripting" stuff :p As you will have guessed. Thanks!
 

Winterbay

Active member
Also, I seem to have had a trouble with X = -1 * Y while X = Y * -1 worked. That might have a been an error on my part in another part of the script though.
 

Theraze

Active member
Remember with math that the order of operations is important... -12 / 7 doesn't mean, well, -12 / 7, it means 12 / 7 and then -. Because addition/subtraction comes last... You're likely getting the same issue on the -1 * Y thing. 1 * Y and then -... but you don't have a number that - is being run against. Likely the code is not initializing that a null value is 0, as that's a dangerous assumption to make.
 

xKiv

Active member
In most language grammars, *unary* - has a higher precedence than any binary operators (meaning that -12/7 evaluates as (-12)/7).

But mafia's ASH parser is (as far as I can tell) a hand-written top-down parser, which is good for code sanity, but not so for grammar sanity.

In this case, I *think* parseExpression sees a negative numeric constant instead of unary minus, and decides to *return* instead of continuing to parse an expression.


ETA: it's possible that adding a space after the - would also make the parser understand it as unary minus, making it work.
 
Last edited:
Top