AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Str to float (https://forums.alliedmods.net/showthread.php?t=306161)

Natsheh 03-19-2018 09:22

Str to float
 
Whats the different between those two natives

str_to_float & floatstr

for some reason str_to_float gives false outputs.

klippy 03-19-2018 10:32

Re: Str to float
 
Where did you even find strfloat?

Quote:

Originally Posted by Natsheh (Post 2583614)
for some reason str_to_float gives false outputs.

That function has been there since the beginning, if it gave wrong results it would've been reported and fixed long ago. You should provide your code and the data you test it on.

Natsheh 03-19-2018 16:59

Re: Str to float
 
1 Attachment(s)
Quote:

Originally Posted by KliPPy (Post 2583625)
Where did you even find strfloat?


That function has been there since the beginning, if it gave wrong results it would've been reported and fixed long ago. You should provide your code and the data you test it on.


Sorry i meant floatstr, here is the code.


Try changing floatstr to str_to_float.

klippy 03-19-2018 17:15

Re: Str to float
 
If you want to prove that a native isn't working properly then create a smallest possible script that proves it. I'm not going to run that, especially because it depends on other plugins which I'd have to search for.
These two natives are nearly equal, but everyone pretty much uses str_to_float - it has a more descriptive name.

Natsheh 03-19-2018 17:40

Re: Str to float
 
Quote:

Originally Posted by KliPPy (Post 2583704)
If you want to prove that a native isn't working properly then create a smallest possible script that proves it. I'm not going to run that, especially because it depends on other plugins which I'd have to search for.
These two natives are nearly equal, but everyone pretty much uses str_to_float - it has a more descriptive name.

Is there any differences between them? If there is can you list them.

klippy 03-19-2018 17:50

Re: Str to float
 
floatstr uses atof from the C standard library, while str_to_float has its own implementaton. atof can accept more input, but is also subject to change. For example in C++11 it had more functionality added (acceps hexadecimal, infinity and NaN values). It seems that floatstr is a relic from AMX days or even earlier as it uses old ways of retrieving strings from Pawn.
In general, for ordinary float values there is absolutely no difference.
atof information: http://www.cplusplus.com/reference/cstdlib/atof/
str_to_float implementation: https://github.com/alliedmodders/amx...tring.cpp#L482


All times are GMT -4. The time now is 12:27.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.