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

How can I check that?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 06-20-2019 , 14:41   How can I check that?
Reply With Quote #1

How can I check if a number is approximately equal to the other? I've been searching for 2 days and I didn't find any post that could help me, so either i'm blind or there aren't much topics about that.
I thought about (Z - Y) < 5 but I don't think it's the best way to do that... maybe.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 06-20-2019 at 15:17.
EFFx is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-20-2019 , 15:29   Re: How can I check that?
Reply With Quote #2

Unless I misunderstand what you mean by "approximately equal", then (Z - Y) < 5 is exactly what you should be doing.
__________________
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 06-20-2019 , 16:03   Re: How can I check that?
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
Unless I misunderstand what you mean by "approximately equal", then (Z - Y) < 5 is exactly what you should be doing.
Approximately equal = almost the same

Someone correct me if I'm wrong but,
PHP Code:
5 Y 3 criteria : < 1

false
= -true 
I think he has to use abs() on X - Y before comparing it.
__________________

Last edited by edon1337; 06-20-2019 at 16:07.
edon1337 is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 06-20-2019 , 16:46   Re: How can I check that?
Reply With Quote #4

Seems that my first idea was correct then, but I think I should make something more "universal". Like: If X value is 90% of the Y value is better, isn't it?

Let's suppose that we have 100 as X and 95 as Y, then we've 95% of the main value, so it's kinda approximated, or is it the same idea as doing X - Y < 5?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-20-2019 , 16:52   Re: How can I check that?
Reply With Quote #5

Quote:
Originally Posted by EFFx View Post
Seems that my first idea was correct then, but I think I should make something more "universal". Like: If X value is 90% of the Y value is better, isn't it?

Let's suppose that we have 100 as X and 95 as Y, then we've 95% of the main value, so it's kinda approximated, or is it the same idea as doing X - Y < 5?
5 - 3 is not the same as 50000 - 30000. Better use a percentage of your choice.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 06-20-2019 , 17:33   Re: How can I check that?
Reply With Quote #6

What do you mean with the same ? Closer to each other?

Are you using floats ?

Then use floatround..


Can you explain what are you doing this for?

Also pick out a better title for your thing.


Edit : best thing is to use your first thing no need to overcomplicate a simple thing
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 06-20-2019 at 18:00.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-20-2019 , 18:53   Re: How can I check that?
Reply With Quote #7

How about this?

This will check if iValueToCheck is >= fVariance percent of iCompareToValue.

PHP Code:
public plugin_init() 
{
    
server_print"Is 95 >= 90%% of 100? = %s" AlmostTheSame100 95 90.0 ) ? "Yes" "No" );
}

bool:AlmostTheSame( const iCompareToValue , const iValueToCheck Float:fVariance )
{
    return 
bool:( ( floatiValueToCheck ) / floatiCompareToValue ) * 100.0 ) >= fVariance );

Code:
Is 95 >= 90% of 100? = Yes

Is 88 >= 90% of 100? = No
__________________
Bugsy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 06-20-2019 , 21:39   Re: How can I check that?
Reply With Quote #8

Quote:
Originally Posted by Natsheh View Post
What do you mean with the same ? Closer to each other?

Are you using floats ?

Then use floatround..


Can you explain what are you doing this for?

Also pick out a better title for your thing.


Edit : best thing is to use your first thing no need to overcomplicate a simple thing
I was trying to make a compass format which makes the directions in a 2D format "rotates" in the hud message, so I was calculing the direction I'm looking at and then add + 15 to the next ones, with that, I would show the hud like this:

v
76
15 30 NE 60 75 E 105 120 SE


So, I asked that because if i'm looking at the direction 76, the next ones will be 91, 106, 121, etc... so with the approximate value, I could change the 91 or 106 to 90 and 105, y'know?


Quote:
Originally Posted by Bugsy View Post
How about this?

This will check if iValueToCheck is >= fVariance percent of iCompareToValue.

PHP Code:
public plugin_init() 
{
    
server_print"Is 95 >= 90%% of 100? = %s" AlmostTheSame100 95 90.0 ) ? "Yes" "No" );
}

bool:AlmostTheSame( const iCompareToValue , const iValueToCheck Float:fVariance )
{
    return 
bool:( ( floatiValueToCheck ) / floatiCompareToValue ) * 100.0 ) >= fVariance );

Code:
Is 95 >= 90% of 100? = Yes

Is 88 >= 90% of 100? = No
I will roger that.


Edit:


Worked, thank you guys, specially Bugsy.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 06-21-2019 at 00:49.
EFFx is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 06-21-2019 , 03:14   Re: How can I check that?
Reply With Quote #9

In that case you just should align your current angle to an increment of 15.
Code:
new const alignedAngle = (floatround(currentAngle + 7.5) / 15) * 15;
Then you can just add or sub 15 a couple of times to get 90, 105 etc.

And please set a proper title.
__________________

Last edited by klippy; 06-21-2019 at 07:50.
klippy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 06-23-2019 , 19:43   Re: How can I check that?
Reply With Quote #10

I'm not bumping, since I already solved it, I'm just answering KliPPy's reply:

That's what I'm doing:

PHP Code:
    iLocationNumber[0] = iCurrentAngle
    iLocationNumber
[1] = iLocationNumber[0] + 15
    iLocationNumber
[2] = iLocationNumber[1] + 15
    iLocationNumber
[3] = iLocationNumber[2] + 15
    iLocationNumber
[4] = iLocationNumber[3] + 15
    iLocationNumber
[5] = iLocationNumber[4] + 15
    iLocationNumber
[6] = iLocationNumber[5] + 15
    iLocationNumber
[7] = iLocationNumber[6] + 15
    iLocationNumber
[8] = iLocationNumber[7] + 15
    iLocationNumber
[9] = iLocationNumber[8] + 15 
Also, isn't your formula wrong? Like, lets say that currentAngle is 175, so it'll be:

floatround(175.0 + 7.5) = 182.0
182.0 / 15 = 12.13
12.13 * 15 = 182.0 ??

Did I misunderstand it?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 06-23-2019 at 19:45.
EFFx is offline
Reply


Thread Tools
Display Modes

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 14:53.


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