Raised This Month: $ Target: $400
 0% 

about percentage


Post New Thread Reply   
 
Thread Tools Display Modes
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 06-24-2012 , 22:17   Re: about percentage
Reply With Quote #11

%d is from decimals values, use %.2f for good to be seen floats.
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-25-2012 , 14:17   Re: about percentage
Reply With Quote #12

This has been completed.

http://forums.alliedmods.net/showthr...36#post1735936
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-25-2012 , 14:19   Re: about percentage
Reply With Quote #13

Quote:
Originally Posted by fysiks View Post
Also, you can never use the comparison operator (==) with floating point numbers.
Why not?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-25-2012 , 18:55   Re: about percentage
Reply With Quote #14

Quote:
Originally Posted by Exolent[jNr] View Post
Why not?
Because a floating point value that has been calculated will "never" equal another floating point value.

For example:

PHP Code:
while( MyFloat != 50.0 )
{
    
MyFloat /* some calculation */;

How often will this be an infinite loop? If the answer is not 0% of the time then my suggestion is valid.
__________________
fysiks is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-25-2012 , 19:40   Re: about percentage
Reply With Quote #15

So you're saying:

Code:
new Float:var = 1.0 / 2.0; if( var == 0.5 ) {     // This block will not be reached }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-25-2012 , 19:51   Re: about percentage
Reply With Quote #16

The "==" operator for floats seems to call floatcmp() native:
PHP Code:
stock bool:operator==(Float:oper1oper2)
    return 
floatcmp(oper1float(oper2)) == 0/* "==" is commutative */ 
though I'm not sure if it's a good way.
PHP Code:
static cell AMX_NATIVE_CALL n_floatcmp(AMX *amx,cell *params)
{
    
/*
    *   params[0] = number of bytes
    *   params[1] = float operand 1
    *   params[2] = float operand 2
    */
    
REAL fAfB;

    
fA amx_ctof(params[1]);
    
fB amx_ctof(params[2]);
    if (
fA == fB)
        return 
0;
    else if (
fA>fB)
        return 
1;
    else
        return -
1;



Last edited by hleV; 06-25-2012 at 19:55.
hleV is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-25-2012 , 23:41   Re: about percentage
Reply With Quote #17

Quote:
Originally Posted by Exolent[jNr] View Post
So you're saying:

Code:
new Float:var = 1.0 / 2.0; if( var == 0.5 ) {     // This block will not be reached }
No, I didn't say that. I said that if it doesn't work 100% of the time then it should never be used.

@hleV: What does amx_ctof do?
__________________
fysiks is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-26-2012 , 06:32   Re: about percentage
Reply With Quote #18

I'd guess ctof stands for cell to float.

EDIT: Hmm, it's cell to real (makes sense looking at the C++ code above, though the naming is kinda incorrect).
Code:
#define amx_ctof g_fn_CellToReal
Code:
extern PFN_CELL_TO_REAL                g_fn_CellToReal;
EDIT 2:
Code:
#if PAWN_CELL_SIZE==32   #define amx_ctof(c)   ( * ((float*)&c) )  /* cell to float */
I'm confused.

Last edited by hleV; 06-26-2012 at 06:37.
hleV is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-26-2012 , 10:14   Re: about percentage
Reply With Quote #19

Tracked down amx_ctof() to use what hleV posted for 32bit.
For 64bit, it ends up calling this function:
Code:
REAL MNF_CellToReal(cell x)
{
	return *(REAL*)&x;
}
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 06-26-2012 , 10:58   Re: about percentage
Reply With Quote #20

PHP Code:
typedef long long int64_t
typedef long int32_t

#if !defined __amd64__
  
typedef int32_t cell
#else
  
typedef int64_t cell
#endif 
amx_ctof converts through AMX Mod X, long to float (32-bit)
amx_ctof converts through AMX Mod X, long long to float (64-bit)
__________________

Last edited by claudiuhks; 06-26-2012 at 11:04.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
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 06:13.


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