![]() |
int is useless
int (-1.5) returns -2, not -1.
int(262143/32768) (which is 7.999969482421875) returns 8, not 7. This is, understandably, brutally murdering all my attempts to script. |
In case anyone else is having this problem:
function trueInt(){ setstring DammitStefan,#v(intThis); intThis=strtofloat(#e(0,indexof(.,#s(DammitStefan) ),#s(DammitStefan))); } |
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
no? so what? :p |
Whatever, int()'s behaviour is obviously inconsistent, it does not work like C's int casts or floor(), and if there is any documentation that explains its behaviour I must have missed it in the past couple of years.
Unless you can explain how to use int() to get the effect that Tyhm is achieving with his horrible string manipulation abomination, stop trolling. |
From my experiences with PHP, when using fractions, you might lose float point precision because it's impossible to express some fractions in a finite number of digits. This commonly affects the use of intVal(), which is the PHP equivalent to GS2's int().
From PHP.net website: Quote:
|
Bee Ess. Any language that thinks 0.1+0.7=0.79 is not a language worth trusting.
|
Quote:
Using large decimals is bound to cause problems. For instance, in GS2 "7.999969482 - 8" produces 0. But, "7.99 - 8" produces -0.01. So, I wouldn't say that int() is useless. It just faces the same problems that other languages face when it comes to floating points. |
I don't think it should round down, it should round towards zero.
The floating point issue has already been covered above. I agree there should be a "floor" in Graal Script like there is in PHP, or the behavior of int should be changed. |
Quote:
|
Quote:
|
Quote:
|
Quote:
I did a quick test on RC. int(7.999) returns 7, but int(7.9999) returns 8. int(7.9998) returns 7, as well as int(7.999899999). Considering that 7.9999 and 7.999969482 have one thing in common, it's safe to assume that when Graal sees ".9999", it'll round up to the nearest whole number. Quote:
|
Quote:
|
Huh. & might work, never tried it before;
The way I've got it set up Now is, it keeps an array of rooms that connect to other rooms; the array index is the room in question, the value at that index is a bitflag of which rooms it connects to (1 means 1, 2 means 2 and not 1, 3 means 2 and 1, 4 means 3, 5 means 3 and 1, etc). When it links two rooms it simply adds the values to combine the list of linked rooms, and then updates not just those 2 rooms but every room that links to those 2 rooms. Moral of the story is, & might work for me, but it's not gonna make me happy; what, I have to revise every int(random(0,2)) now to have a special case for if it returns 2?! |
Quote:
|
Quote:
PHP Code:
Quote:
|
Pseudo-bitwise operation on what amounts to floating point numbers are a bit scary. :\
|
Interesting stuff on the whole rounding issue to anyone who is interested: http://wiki.php.net/rfc/rounding
|
| All times are GMT +2. The time now is 11:43 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.