Author Topic: Approximation  (Read 8330 times)

0 Members and 1 Guest are viewing this topic.

Offline Skirmant

  • Made Man
  • ***
  • Posts: 134
    • View Profile
Approximation
« on: January 20, 2010, 07:41:21 pm »
How do you approximate on mirc?

Lets say we have a number 4.6 after approximation it would be 5.
If we have a number 4.2 after approximation it would be 4.

Any ideas how to do this?
 
« Last Edit: January 20, 2010, 08:02:06 pm by Skirmant »

Offline thijn

  • LU testers
  • VC:MP Veteran
  • *
  • Posts: 667
  • Im proud to be pro.
    • View Profile
    • Vice Underdogs
Re: Approximation
« Reply #1 on: January 20, 2010, 08:04:04 pm »
$round?

Offline Kirke

  • Street Thug
  • *
  • Posts: 14
    • View Profile
Re: Approximation
« Reply #2 on: January 20, 2010, 08:13:51 pm »
You want to "round to next nearest whole number"

You need to create your own procedure to do the following;

$ceil(N) -  Returns N rounded to the next highest integer.

$floor(N) - Returns N rounded to the next lowest integer.


I did it for you :-)


alias SetWholeNumber !return $iif($gettok($1,2,46) >= 5,$ceil($1),$floor($1))

Type //echo -a $SetWholeNumber(4.6) and //echo -a $SetWholeNumber(4.2)

Offline Skirmant

  • Made Man
  • ***
  • Posts: 134
    • View Profile
Re: Approximation
« Reply #3 on: January 20, 2010, 08:21:22 pm »
alias SetWholeNumber !return $iif($gettok($1,2,46) >= 5,$ceil($1),$floor($1))

Ye... Dosn't work. It always returns 8 D=

$round?

I'm not sure how $round works. If I do $round(1.6) it returns 1.6

Offline Kirke

  • Street Thug
  • *
  • Posts: 14
    • View Profile
Re: Approximation
« Reply #4 on: January 20, 2010, 08:27:43 pm »
come on, this is basic maths

http://www.mathwizz.com/fractions/help/help13.htm

that alias i gave you works perfectly fine.

Code: [Select]
alias SetWholeNumber !return $iif($gettok($1,2,46) >= 5,$ceil($1),$floor($1))
always returns 8 ?

what the heck are you typing ?

type //echo -a $SetWholeNumber(4.2)

//echo -a $SetWholeNumber(4.6)

or you on drugs by any chance ?

Offline Skirmant

  • Made Man
  • ***
  • Posts: 134
    • View Profile
Re: Approximation
« Reply #5 on: January 20, 2010, 08:31:39 pm »
or you on drugs by any chance ?

LOL!

I added
Code: [Select]
alias SetWholeNumber !return $iif($gettok($1,2,46) >= 5,$ceil($1),$floor($1))
And i typed //echo -a $SetWholeNumber(4.6)

Returns 8.

(BTW math for me is not an issue I'm good at it)
« Last Edit: January 20, 2010, 08:34:11 pm by Skirmant »

Offline Kirke

  • Street Thug
  • *
  • Posts: 14
    • View Profile
Re: Approximation
« Reply #6 on: January 20, 2010, 08:33:34 pm »
returns 5 for me, just like it should do.

not sure why its retunging 8 for you, make your own.


you know what you need to do now,
 use
$celi and $floor read the help manual, come on, its basic maths

Offline Skirmant

  • Made Man
  • ***
  • Posts: 134
    • View Profile
Re: Approximation
« Reply #7 on: January 20, 2010, 09:02:23 pm »
$celi and $floor read the help manual, come on, its basic maths

Nah its extremely basic maths, but basic scripting.

Here's a script I made and it works :D
 
Code: [Select]
alias vcmp.whole {
  if ($1 < $calc($floor($1) + 0.5)) !return $floor($1)
  else !return $ceil($1)
}   

Thanks for informing me about $ceil and $floor  :P

Offline Boss

  • VC:MP Beta Tester (inactive)
  • Made Man
  • *
  • Posts: 229
  • Boss
    • View Profile
    • TDH Clan Site
Re: Approximation
« Reply #8 on: January 20, 2010, 09:05:50 pm »
You switch to pawn, you declare a variable f and you use floatround(f);. Simple as that!

Offline Skirmant

  • Made Man
  • ***
  • Posts: 134
    • View Profile
Re: Approximation
« Reply #9 on: January 20, 2010, 09:07:27 pm »
You switch to pawn, you declare a variable f and you use floatround(f);. Simple as that!

Eh... What? Anyways I think I'm better out with mirc  ;D

Offline Kirke

  • Street Thug
  • *
  • Posts: 14
    • View Profile
Re: Approximation
« Reply #10 on: January 20, 2010, 09:14:32 pm »
Code: [Select]
alias SetWholeNumber !return $iif($gettok($1,2,46) >= 5,$ceil($1),$floor($1))
care to explain how that would ever return 8 if passed the value 4.6 ?

its using $gettok to check if the value has a remainder 5 or over

if $true return the next highest integer. $celi

if $false the next lowest integer. $floor

Offline Skirmant

  • Made Man
  • ***
  • Posts: 134
    • View Profile
Re: Approximation
« Reply #11 on: January 20, 2010, 09:20:01 pm »
Hmm... Well I just tried your alias a few more times and I found out that if that alias doesn't have "vcmp." attached to it it always returns 8. Weird huh?

When I attached .vcmp it worked
« Last Edit: January 20, 2010, 09:23:45 pm by Skirmant »

Offline Kirke

  • Street Thug
  • *
  • Posts: 14
    • View Profile
Re: Approximation
« Reply #12 on: January 20, 2010, 09:22:12 pm »
i would quite like to know how on earth your getting it to return 8.

its only returning either $celi or $floor of your passed parameter (in this case 4.6)

PS, would other people check this works:

Code: [Select]
alias SetWholeNumber !return $iif($gettok($1,2,46) >= 5,$ceil($1),$floor($1))
//echo -a $SetWholeNumber(4.6) - should return 5

//echo -a $SetWholeNumber(4.2) - should return 4

Offline Kirke

  • Street Thug
  • *
  • Posts: 14
    • View Profile
Re: Approximation
« Reply #13 on: January 20, 2010, 09:24:27 pm »
ok, your talking utter rubbish now. you've wasted a whole thread when the example i gave you worked perfectly fine. (which has now probably confused other people)

Offline Skirmant

  • Made Man
  • ***
  • Posts: 134
    • View Profile
Re: Approximation
« Reply #14 on: January 20, 2010, 09:31:13 pm »
ok, your talking utter rubbish now. you've wasted a whole thread when the example i gave you worked perfectly fine. (which has now probably confused other people)

I think you're over reacting buddy. I'm not talking rubbish. For some reason your example doesn't work for me with out "vcmp." attached to it and I really don't want to make a big deal about it.

Code: [Select]
alias SetWholeNumber !return $iif($gettok($1,2,46) >= 5,$ceil($1),$floor($1))

//echo -a $SetWholeNumber(4.6)

Returns 8

Code: [Select]
alias vcmp.SetWholeNumber !return $iif($gettok($1,2,46) >= 5,$ceil($1),$floor($1))

//echo -a $vcmp.SetWholeNumber(4.6)

Returns 5

finnal post in this thread
« Last Edit: January 20, 2010, 09:42:20 pm by Skirmant »