Computer Science Canada

Integer overflow problem with turing's trig functions.

Author:  CodeMonkey2000 [ Fri Aug 24, 2007 7:00 pm ]
Post subject:  Integer overflow problem with turing's trig functions.

When I run this I keep getting an integer overflow error.

Turing:

fcn tand (angle : real) : real
    result sind (angle) / cosd (angle)
end tand
put round (tand (90))


How do I get around this? The number you get in that function isn't even that big (in fact it's quite small), why is it giving me this error? Oh and I need to deal with integers. Using just real variables won't help me.

Author:  rizzix [ Fri Aug 24, 2007 7:04 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

tand(90) = infinity =\ how could it be small?

Actually why isin't it complaining of div by zero?

Author:  CodeMonkey2000 [ Fri Aug 24, 2007 7:09 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

Oh right use radian Razz

Author:  Clayton [ Fri Aug 24, 2007 7:10 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

And just to clarify:

tand 90 = sind 90 / cosd 90
tand 90 = 1 / 0

That's why it doesn't work Confused

Author:  rizzix [ Fri Aug 24, 2007 7:12 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

Radians or degrees, either one would result in Infinity.

My concern is why isin't cosd(90) = 0???

Author:  Clayton [ Fri Aug 24, 2007 7:58 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

I'm not sure Confused Turing represents cosd (90) as 1.22 x 10^-16, yet sind (90) = 1

Author:  CodeMonkey2000 [ Fri Aug 24, 2007 10:03 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

Another strange thing is that tand(90) won't give you an error. Only when you try to convert it in to an integer through round,ceil or floor will you get an error. So it realizes its mistake when you attempt to convert it.

Author:  Clayton [ Fri Aug 24, 2007 10:09 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

Uh... tand(90) definitely gives an error in the way of "Quit #51"

Author:  CodeMonkey2000 [ Fri Aug 24, 2007 10:13 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

That's strange, on my computer it gave me:

8.16423 x10^18

Author:  rizzix [ Fri Aug 24, 2007 10:31 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

You're using a different version of Turing. I'm guess ing ver < 4.1

Author:  Prince Pwn [ Sat Aug 25, 2007 1:45 am ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

How do u ppls know how to use tangent and stuff. I dont understand any of that.

Author:  Nick [ Sat Aug 25, 2007 7:52 am ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

you learn in math... i think gr 11 advanced or gr 12

Author:  Clayton [ Sat Aug 25, 2007 8:59 am ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

@momop, your avatar is too large, please resize it to something smaller.

@rizzix, he's probably the one using 4.1, I'm using 4.0.5

@Prince Pwn, Grade 10 math you start to learn trig... at least... you should have Confused

Author:  CodeMonkey2000 [ Sat Aug 25, 2007 9:32 am ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

I have turing 4.0.3.

Author:  CodeMonkey2000 [ Sat Aug 25, 2007 9:37 am ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

But that's good enough. Trig really isn't that hard. It's not hard to go further than what they teach you either. I'm going into grade 11.

Author:  Nick [ Sat Aug 25, 2007 9:41 am ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

hmm i guess a google search is always do-able lol i just wasn't too good at trig... always did the operation in the wrong order Razz and too ppl out there saying BEDMAS!!! it was more advanced than bedmas

Author:  Aziz [ Sat Aug 25, 2007 12:26 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

Make sure this doesn't wack out in OpenT!

Author:  rizzix [ Sat Aug 25, 2007 12:40 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

OpenT would potentially (we haven't implemented function invocation yet...) use java.lang.Math's trig functions. As far as I'm concerned, those functions are extremely well defined and have been widely used throughout the world, with little to no problem. Thus it surely wouldn't wack out in OpenT Smile

Oh, but lately there's been a lot of talk about precision and I believe we might introduce new types in OpenT: strict_int4, strict_real4, etc. These types would potentially behave exactly as the IEEE describes them, but additionally they might throw exceptions from common arithmetic operations on loss of precision. One would use them when they need precise arithmetic, but not when performance is critical.

But strict numerical types are not a top priority right now. OTOH compile time precision evaluation IS.. so you will not see such fancy feature for a while.

Author:  Aziz [ Sat Aug 25, 2007 12:46 pm ]
Post subject:  RE:Integer overflow problem with turing\'s trig functions.

"OTOH compile time precision evaluation IS", didn't understand a word of it.

Anyways Smile I failed to actually think my previous post through and I see how right you are Razz

Author:  rizzix [ Sat Aug 25, 2007 2:14 pm ]
Post subject:  Re: RE:Integer overflow problem with turing\'s trig functions.

Aziz @ Sat Aug 25, 2007 12:46 pm wrote:
"OTOH compile time precision evaluation IS", didn't understand a word of it.


Just something we're working on right now Razz Basically, we're trying to warn the user on such cases:

Turing:
var a : int := 0.5  % you loose information here
and
Turing:
var a : real := -2147483647 % loss of precision here too!


Read issue #11 for more details.


: