Thyme math issues
7 posts • Page 1 of 1
Thyme math issues
1. Division of a float with zero returns +inf.
2. math.toInt(+inf) and math.toInt(NaN) return -2147483648.
Examples:
2. math.toInt(+inf) and math.toInt(NaN) return -2147483648.
Examples:
- Code: Select all
> 0.0 / 0
+inf
> 1.0 / 0
+inf
> math.toInt(+inf)
-2147483648
> math.toInt(NaN)
-2147483648
-

Ivan - Posts: 203
- Joined: Tue Oct 06, 2009 2:01 pm
- Location: Croatia
Re: Thyme math issues
The problem with this is that there is 2 options; diving by 0 can either return 0 or +inf.
although you are taught in school that when you divide be 0, you get 0, when actually, you can put millions upon billions of 0 into any number, this +inf is technically correct, while 0 is more of a standard in school teaching.
although you are taught in school that when you divide be 0, you get 0, when actually, you can put millions upon billions of 0 into any number, this +inf is technically correct, while 0 is more of a standard in school teaching.
When asking for help, READ THE STICKIES!
- electronicboy
- Posts: 1694
- Joined: Mon Aug 31, 2009 6:18 pm
Re: Thyme math issues
ohh, common, just add <>0 check in your code.
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Thyme math issues
To electronicboy:
Thanks for your reply! I am aware of that. The problem was more with math.toInt(+inf) and 0.0/0 which should give NaN (or 0 to keep is simple) because 0 : x = 0, x : x = 1 and x : 0 = ±inf.
To Kilinich:
The code would look neater if there was no need for <>0 check.
Thanks for your reply! I am aware of that. The problem was more with math.toInt(+inf) and 0.0/0 which should give NaN (or 0 to keep is simple) because 0 : x = 0, x : x = 1 and x : 0 = ±inf.
To Kilinich:
The code would look neater if there was no need for <>0 check.
-

Ivan - Posts: 203
- Joined: Tue Oct 06, 2009 2:01 pm
- Location: Croatia
Re: Thyme math issues
The value of +inf or NaN in hex is 0x80000000, when converted to signed int, literally translates to the most negative number. Ints don't have +inf or NaN, so unless you want the program to crash or throw an exception, that's the only option you have. Of course, you can do the <>0 check instead. Algodoo wasn't designed to handle poor scripting.
-

Conundrumer - Posts: 344
- Joined: Mon Aug 31, 2009 5:55 pm
- Location: NYC
Re: Thyme math issues
Thanks for clarifying me some things, Conundrummer.
-

Ivan - Posts: 203
- Joined: Tue Oct 06, 2009 2:01 pm
- Location: Croatia
7 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 11 guests




