![]() |
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:
|
| All times are GMT +2. The time now is 10:54 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.