Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   float() (https://forums.graalonline.com/forums/showthread.php?t=134260228)

xXziroXx 08-17-2010 03:10 AM

float()
 
Can anyone tell me if this is supposed to happen and if so, why?

PHP Code:

float(123) = 123
float
("123") = 123
float
("str") = -1
float
("str123") = -1
float
("123str") = 123 

Note the very last one. If a string starts with numbers, the float() command thinks it's a number, and I find this very annoying and misleading. If it is indeed a bug with the engine, could it be fixed please?

WhiteDragon 08-17-2010 03:29 AM

This is known behavior, and I think intentional (would need to contact Stefan for reasoning). It shouldn't be hard to make your own float function which calls the internal float only in the case where all the characters of the string are integers (or decimal points). Not sure about scientific notation and how it handles that.

fowlplay4 08-17-2010 03:45 AM

Well this is just silly.

PHP Code:

echo("123str" "123str"); // echos 246 


xXziroXx 08-17-2010 03:47 AM

Quote:

Originally Posted by WhiteDragon (Post 1594759)
This is known behavior, and I think intentional (would need to contact Stefan for reasoning). It shouldn't be hard to make your own float function which calls the internal float only in the case where all the characters of the string are integers (or decimal points). Not sure about scientific notation and how it handles that.

I'd rather have the default float() function work like the way it, at least in my opinion, is supposed to work.

WhiteDragon 08-17-2010 03:48 AM

Quote:

Originally Posted by xXziroXx (Post 1594762)
I'd rather have the default float() function work like the way it, at least in my opinion, is supposed to work.

It'd involve reworking literally all the string->number casting in GS which could introduce bugs. (Not saying that I disagree with your motive, it's just unrealistic.)

xXziroXx 08-17-2010 04:31 AM

Quote:

Originally Posted by WhiteDragon (Post 1594764)
which could introduce bugs.

More like fix current bugs and have it work like supposed too after that. Maybe Stefan could even write something up that'll only affect how float() handles things.

fowlplay4 08-17-2010 04:34 AM

int("123str") should really return -1 too

-Ramirez- 08-17-2010 04:36 AM

Quote:

Originally Posted by WhiteDragon (Post 1594764)
It'd involve reworking literally all the string->number casting

This is data conversion, not casting.

xXziroXx 08-17-2010 04:41 AM

Quote:

Originally Posted by fowlplay4 (Post 1594778)
int("123str") should really return -1 too

Definitely. Just because a string STARTS with numbers doesn't mean it's a number.

Admins 08-17-2010 05:21 PM

This is the same behaviour as the various C functions for converting a string to integer or floating point value.

xXziroXx 08-17-2010 05:30 PM

Quote:

Originally Posted by Stefan (Post 1594875)
This is the same behaviour as the various C functions for converting a string to integer or floating point value.

Perhaps, but it doesn't make any sense, you gotta agree on that much. At the very least could you add another function that doesn't think 123string49foobar equals the number 123?

Loriel 08-17-2010 05:41 PM

Why the hell does Stefan have to do all the programming for you infants

stefan can you add a function to tie my shoelaces :'(

Fulg0reSama 08-17-2010 05:49 PM

Quote:

Originally Posted by Loriel (Post 1594882)
Why the hell does Stefan have to do all the programming for you infants

stefan can you add a function to tie my shoelaces :'(

Too advanced Loriel. Make them yourself. :mad:

Liberated 08-17-2010 05:55 PM

Quote:

Originally Posted by Loriel (Post 1594882)
Why the hell does Stefan have to do all the programming for you infants

because we pay him for it?

Loriel 08-17-2010 06:04 PM

Quote:

Originally Posted by Liberated (Post 1594885)
because we pay him for it?

okay so since I am paying him too i am paying him not to change float() or add a new function or whatever


All times are GMT +2. The time now is 10:14 AM.

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