 |
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: Mon Oct 09, 2006 7:06 am
[1.09] Incorrectly displayed calculations using exponentials |
#say %eval((1.0)/2000)
0.0005
#say %eval((1.0)/20000)
-5
Seems to be forgetting to format the number correctly when it's small
And if you then use the number
#say (%eval(((1.0)/20000))*100)
It's returning -500 (rather than 0.005) |
|
_________________ CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;) |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Oct 11, 2006 2:25 am |
CMUD wasn't handling the exponential notation properly. Actually, doing
#say (1.0/20000)
was working fine. And remember that you don't need %eval if you put () around expressions. Adding %eval just adds another evaluation step that isn't necessary and slows down your scripts.
In this case, the above result was "5E-5". So, when this string was passed to %eval, it was trying to subtract 5 from the string 5E which is undefined.
But I've fixed 1.10 so that the parser properly handles exponential notation, so when %eval sees 5E-5 it recognizes it as a floating point value instead of a subtraction operation.
Also, your last example is incorrect...you've got all sorts of extra evaluations going on. First you have the (1.0)/20000 evaluation, then the %eval of that, then that result*100. It would be much simpler to just use
#say ((1.0/20000)*100)
which also works fine in v1.10. |
|
|
 |
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: Wed Oct 11, 2006 9:18 am |
I think I probably tried to use an %eval at first when I did 1/20000, and it came out as 0. Then when I changed to 1.0 to force the float then I didn't think to remove the eval. The 2nd example was just showing that the -5 was being used in the next part of the calculation. Anyways though, good that it's fixed, and I'll lay off the extra %eval's in future ;)
|
|
_________________ CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;) |
|
|
 |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|