Problem with math in maxscript

Problem with math in maxscript

bobandoug
Explorer Explorer
1,065 Views
6 Replies
Message 1 of 7

Problem with math in maxscript

bobandoug
Explorer
Explorer

Why does this return a zero rather than the expected value?

 

(3*8*10^(7-7.5))

 

Maxscript gives me a zero, but I'm expecting 7.5894663844

 

many thanks

Bob

0 Likes
Accepted solutions (1)
1,066 Views
6 Replies
Replies (6)
Message 2 of 7

Steve_Curley
Mentor
Mentor
Because it is calculating (3*8*10) ^ (7-7.5) rather than 3*8*(10^(7-7.5)). Generally safer, in any language, to be explicit (parenthesize the calculation to force what you need) rather than relying on built-in rules of operator precedence (which may or may not be correct - school was a long, long time ago... ;))

[Edit]Actually, it's wrong anyway - shouldn't 0 but 0.064549722[/Edit]

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 7

bobandoug
Explorer
Explorer

Hello Steve_Curley

I thought that too. When I try what you suggested I still get a zero rather than the correct answer.

 

I think I'm not using math correctly in max script.


Thank you

 

edit google gets it right, but maxscript doesn't. click here to see Google get the correct answer

 

0 Likes
Message 4 of 7

Steve_Curley
Mentor
Mentor
Accepted solution
It's a quirk of Maxscript. If the number being raised to a power (not the power itself) is an integer then the result is a truncated integer. Try again with 10.0 instead of 10.
(3*8*10.0^(7-7.5)) gives the correct answer. 10^(7-7.5) was being truncated to 0 and anything ^ 0 is 0 so the entire result was 0.

Look up "number values" in the Maxscript help - I had to do that to work out what was wrong.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

Message 5 of 7

Steve_Curley
Mentor
Mentor
Note - this should have been in the Maxscript forum. Once you've replied I'll move it there.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 6 of 7

bobandoug
Explorer
Explorer

Steve_Curley thank you for the answer. I guess putting the .0 in forces maxscript to evaluate it as a float and not as an integer.

 

Thanks for the help!

 

I did look for a maxscript forum here, but I couldn't see a section about maxscript. I must need new glasses 🙂

 

 

 

 

0 Likes
Message 7 of 7

Steve_Curley
Mentor
Mentor
Programming. Maxscript and the SDK used to be separate forums, now they aren't (and I keep forgetting that...).

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes