Graal Forums  

Go Back   Graal Forums > Graal V6 forums > Bug Report
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 01-26-2009, 01:15 AM
Tyhm Tyhm is offline
Psionic Youth
Tyhm's Avatar
Join Date: Mar 2001
Location: Babord, West Graal Deaths:1009 Kills:1
Posts: 5,635
Tyhm will become famous soon enough
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.
__________________
"Whatever," said Bean, "I was just glad to get out of the toilet."

"Power does not corrupt. Fear corrupts, perhaps the fear of a loss of power."- John Steinbeck
"I'm only acting retarded, what's your excuse?" queried the Gord.
- My pet, the Levelup Gnome

http://forums.graalonline.com/forums...&postcount=233
Reply With Quote
  #2  
Old 01-26-2009, 01:34 AM
Tyhm Tyhm is offline
Psionic Youth
Tyhm's Avatar
Join Date: Mar 2001
Location: Babord, West Graal Deaths:1009 Kills:1
Posts: 5,635
Tyhm will become famous soon enough
In case anyone else is having this problem:

function trueInt(){
setstring DammitStefan,#v(intThis);
intThis=strtofloat(#e(0,indexof(.,#s(DammitStefan) ),#s(DammitStefan)));
}
__________________
"Whatever," said Bean, "I was just glad to get out of the toilet."

"Power does not corrupt. Fear corrupts, perhaps the fear of a loss of power."- John Steinbeck
"I'm only acting retarded, what's your excuse?" queried the Gord.
- My pet, the Levelup Gnome

http://forums.graalonline.com/forums...&postcount=233
Reply With Quote
  #3  
Old 01-26-2009, 05:07 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by Tyhm View Post
int (-1.5) returns -2, not -1.

This is, understandably, brutally murdering all my attempts to script.
int() rounds decimals down, and thus -1.5 becomes -2 in the same way 1.5 would become 1. If it bothers you that much, you can always abs() it prior do the int().
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto

Last edited by xXziroXx; 01-26-2009 at 06:13 PM..
Reply With Quote
  #4  
Old 01-26-2009, 05:31 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by xXziroXx View Post
Quote:
Originally Posted by Tyhm
int(262143/32768) (which is 7.999969482421875) returns 8, not 7.
int() rounds decimals down
Reply With Quote
  #5  
Old 01-26-2009, 06:10 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by Loriel View Post
Right.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #6  
Old 01-26-2009, 06:11 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by xXziroXx View Post
int() rounds decimals down, and thus -1.5 becomes -2 in the same way 1.5 would become 1. If it bothers you that much, you can always abs() it prior do the int().
returns 7.999969482
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #7  
Old 01-26-2009, 06:12 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by Deas_Voice View Post
returns 7.999969482
I never replied to the 7.99adjhafgafe whatever, now did I?
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #8  
Old 01-26-2009, 06:14 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by xXziroXx View Post
I never replied to the 7.99adjhafgafe whatever, now did I?
uhm.....
no?
so what?
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #9  
Old 01-26-2009, 07:48 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
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.
Reply With Quote
  #10  
Old 01-27-2009, 02:24 AM
DarkReaper0 DarkReaper0 is offline
No.
DarkReaper0's Avatar
Join Date: May 2005
Location: Texas,USA
Posts: 344
DarkReaper0 will become famous soon enough
Send a message via MSN to DarkReaper0
Quote:
Originally Posted by xXziroXx View Post
I never replied to the 7.99adjhafgafe whatever, now did I?
No, but if you paid attention you'd realize not recognizing that point 'brutally murdered' your response.
Reply With Quote
  #11  
Old 01-26-2009, 11:00 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
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:
Warning
Floating point precision

It is typical that simple decimal fractions like 0.1 or 0.7 cannot be converted into their internal binary counterparts without a small loss of precision. This can lead to confusing results: for example, floor((0.1+0.7)*10) will usually return 7 instead of the expected 8, since the internal representation will be something like 7.9.

This is due to the fact that it is impossible to express some fractions in decimal notation with a finite number of digits. For instance, 1/3 in decimal form becomes 0.3 (repeating).

So never trust floating number results to the last digit, and never compare floating point numbers for equality. If higher precision is necessary, the arbitrary precision math functions and gmp functions are available.
Note: floor() is a PHP function that rounds a number down to the whole number closest to zero... which is probably closer to GS2's int() than intVal(), since intVal() accepts a base (defaults to base 10) parameter.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #12  
Old 01-27-2009, 01:40 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by LoneAngelIbesu View Post
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:


Note: floor() is a PHP function that rounds a number down to the whole number closest to zero... which is probably closer to GS2's int() than intVal(), since intVal() accepts a base (defaults to base 10) parameter.
Nice theory, except booth floor and intval get 262143/32768 right.
Reply With Quote
  #13  
Old 01-27-2009, 03:20 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Loriel View Post
Nice theory, except booth floor and intval get 262143/32768 right.
In PHP, maybe. We're talking about GS2 here, so we have to assume that it's going to screw up easily with large decimals, as seen when it can't correctly subtract 8 from 7.999969482. Obviously, it's rounding 7.999969482 to 8, which is also why int(7.999969482) returns 8 instead of 7.

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:
Originally Posted by Tyhm View Post
I'd love to, but it's difficult to determine if the bitflag 262143 contains 32768 (2^15th) or not without doing a little division.
What are you trying to accomplish, exactly? Perhaps if you showed us the problem in context, somebody might be able to figure something out (unless you're fine with using your work-around).
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #14  
Old 01-26-2009, 11:29 PM
Tyhm Tyhm is offline
Psionic Youth
Tyhm's Avatar
Join Date: Mar 2001
Location: Babord, West Graal Deaths:1009 Kills:1
Posts: 5,635
Tyhm will become famous soon enough
Bee Ess. Any language that thinks 0.1+0.7=0.79 is not a language worth trusting.
__________________
"Whatever," said Bean, "I was just glad to get out of the toilet."

"Power does not corrupt. Fear corrupts, perhaps the fear of a loss of power."- John Steinbeck
"I'm only acting retarded, what's your excuse?" queried the Gord.
- My pet, the Levelup Gnome

http://forums.graalonline.com/forums...&postcount=233
Reply With Quote
  #15  
Old 01-26-2009, 11:35 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Tyhm View Post
Bee Ess. Any language that thinks 0.1+0.7=0.79 is not a language worth trusting.
It's probably more complex than you think it is. PHP is a very good language. The point I was trying to make, though, was that you should try and not use non-terminating decimals, or at least round them to terminating decimals.

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.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan

Last edited by LoneAngelIbesu; 01-26-2009 at 11:49 PM..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.