forums

TNT Basic Forums > Bugs!
Maths error in sqrt operation
< Last Thread     Next Thread >
Author
Thread        Post A Reply

04-01-2003 12:26

Posted by:
Machi

Click Here to Email Machi   Find more posts by Machi

I haven't logged a bug report in ... um, well, since yesterday ...

This one had me confused, because I wasn't getting the right trigonometric calculation happening. As you can see if you run the little program inserted below, the sqrt operation doesn't work properly (whilst I can find many values that it does work for, it is pretty easy to find values that it doesn't). As you can also see, the exponentiation operation appears to work just fine - so there is a ready work around, however this is an error that will have significant consequences to many programs.

Error occurs in both OSX and classic, using v1.12

'Program starts
float this
float that
float theother

this = 22/9

that = this ^ 2
theother = that
that = sqrt(that)
theother = theother ^ 0.5

print "this",this
print "that",that
print "theother",theother

end
'Program ends

04-01-2003 12:42

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

yeah, I saw that to but ^0.5 worked, so I didn' t bother

04-01-2003 19:49

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

Fixed

Ahh well spotted. I've had a look at it and fixed it. We were truncating the float you passed in to an int before doing the sqrt on it - hence the loss of accuracy - and why it worked in our test cases ( print sqrt(25) etc).

Thanks for that,

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.