Raised This Month: $51 Target: $400
 12% 

0.0 <= 0.0 equals to false?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viña del Mar, Chile
Old 04-20-2014 , 22:14   0.0 <= 0.0 equals to false?
Reply With Quote #1

PHP Code:
                    static Float:flBlendbool:bSum
                    server_print
("prepare sum=%d blend=%f"_:bSumflBlend)
                    
                    if(
bSum)
                        
flBlend += 0.1
                    
else
                        
flBlend -= 0.1
                    
                    
if(flBlend >= 1.0)
                        
bSum false
                    
if(flBlend <= 0.0)
                        
bSum true
                        
                    server_print
("modified sum=%d blend=%f"_:bSumflBlend
*no need to show more code, so stop those "this is an xy problem" comments and that shit*



so, you can guess that on the green block, the "if(flBlend >= 1.0)" statement works and sum is set to 0 (false)

but, what happens on the red block?

flBlend is 0.1, and bSum is false, so it should decrease it in 0.1 resulting 0.0, but...
PHP Code:
                              if(bSum)
                        
flBlend += 0.1
                    
else
                        
flBlend -= 0.1 /* = 0.0 */
                    
                    
if(flBlend >= 1.0)
                        
bSum false
                    
if(flBlend /* 0.0 */ <= 0.0//lolwat
                        
bSum true // this isn't called 

the "if(flBlend <= 0.0)" meaning it's "if(0.0<= 0.0)" isn't validated (because it said that sum is 0 and blend is also 0.0), so wtf amxx, is this "correct" ?
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross

Last edited by meTaLiCroSS; 04-20-2014 at 23:24.
meTaLiCroSS is offline
Xunfop
Member
Join Date: Mar 2012
Location: 97Club
Old 04-20-2014 , 22:54   Re: 0.0 <= 0.0 equals to false?
Reply With Quote #2

IEEE 754
Xunfop is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 04-20-2014 , 23:09   Re: 0.0 <= 0.0 equals to false?
Reply With Quote #3

PHP Code:
new Float:Value 0.0Float:Other 0.0;

if (
Value <= 0.0)
{
  
server_print("0");
}

if (
Value <= Other)
{
  
server_print("1");

Output:

PHP Code:
0

I don't really understand what you are trying to explain into the first message, but I am sure stock Float: operator <= (Float: fA, Float: fB) and native floatcmp(Float: fA, Float: fB) works properly.

Try to use fl1 = fl1 + fl2 instead of fl1 += fl2.
__________________

Last edited by claudiuhks; 04-20-2014 at 23:19.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 04-20-2014 , 23:10   Re: 0.0 <= 0.0 equals to false?
Reply With Quote #4

Not sure why that is happening. But can be fixed by changing <= 0.0 to < 0.1
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.

Last edited by hornet; 04-20-2014 at 23:37.
hornet is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viña del Mar, Chile
Old 04-20-2014 , 23:11   Re: 0.0 <= 0.0 equals to false?
Reply With Quote #5

Quote:
Originally Posted by hornet View Post
Not sure why that is, but can be fixed by changing <= 0.0 to < 0.1
Yeah, just did it after posting this, but I'm still thinking why that code failed

Quote:
Originally Posted by claudiuhks View Post
I don't really understand what you are trying to explain into the first message, but I am sure stock Float: operator <= (Float: fA, Float: fB) and native floatcmp(Float: fA, Float: fB) works properly.
Buddy, i know that... can you please see again the post?
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross

Last edited by meTaLiCroSS; 04-20-2014 at 23:13.
meTaLiCroSS is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 04-20-2014 , 23:15   Re: 0.0 <= 0.0 equals to false?
Reply With Quote #6

Quote:
Originally Posted by hornet View Post
Not sure why that is, but can be fixed by changing <= 0.0 to < 0.1
Real numbers usually work with more decimals. 0.0 is lower than 0.1 but lower than 0.0005 aswell.
If a number is real and you define it positive, you can't say it's higher than -1, cause it can be -0.002. You need to say that it's higher or equal to 0.

Quote:
Originally Posted by meTaLiCroSS View Post
Buddy, i know that... can you please see again the post?
My message has been updated. OK, will take a look again.
__________________

Last edited by claudiuhks; 04-20-2014 at 23:18.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viña del Mar, Chile
Old 04-20-2014 , 23:29   Re: 0.0 <= 0.0 equals to false?
Reply With Quote #7

Quote:
Originally Posted by claudiuhks View Post
Real numbers usually work with more decimals. 0.0 is lower than 0.1 but lower than 0.0005 aswell.
If a number is real and you define it positive, you can't say it's higher than -1, cause it can be -0.002. You need to say that it's higher or equal to 0.



My message has been updated. OK, will take a look again.
You're right. But, strange thing is that no more decimals are added to the num.

The code that I gave above shows everything, numbers calculated are 0.0, 0.1, 0.2, 0.3, ... 0.9, 1.0, there's no other minor number like 0.05, or anything else, it's just the same number plus 0.1 or -0.1, so I'm still not understanding, you can see the printed screen above, flBlend = 0.0, and bSum = false, so the "flBlend <= 0.0" check was avoided
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 04-21-2014 , 06:58   Re: 0.0 <= 0.0 equals to false?
Reply With Quote #8

0.0-0.1 = -0.099999?
jimaway is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 04-21-2014 , 07:51   Re: 0.0 <= 0.0 equals to false?
Reply With Quote #9

Could this have an effect?
I did set it to 65536 and I still got the same -0.099999 though.
core.ini
Code:
; Plugin optimization flags - add these up to get what you want
; lowering these may stop crashes on very old CPUs
; set 65536 to disable optimizer, NOT 0!
;-------------
; 1 - float arithmetic
; 2 - float comparisons
; 4 - float rounding
optimizer	7
__________________

Last edited by Black Rose; 04-21-2014 at 07:56.
Black Rose is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 04-21-2014 , 14:05   Re: 0.0 <= 0.0 equals to false?
Reply With Quote #10

I find that it is useless to use == and =something operator for floats check.

When you do something like this
a = 0.0
if(a) // called

But when you use +-/* then there will be no accurate float.
=(something) check will be useless.

Last edited by .Dare Devil.; 04-21-2014 at 14:07.
.Dare Devil. is offline
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 -4. The time now is 22:00.


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