YesNoOk
avatar

Ceil (math) and Floor (math) (Triggers) (Read 11142 times)

Started by JustNoPoint, September 13, 2015, 01:11:38 am
Share this topic:
Ceil (math) and Floor (math) (Triggers)
New #1  September 13, 2015, 01:11:38 am
  • ******
    • www.justnopoint.com/
Implements the "ceiling" and "floor" functions, respectively. Ceil returns the least integer which is greater than or equal to the specified argument, while Floor returns the greatest integer less than or equal to its argument.

Format:
    1.) ceil(exprn)
    2.) floor(exprn)
Arguments:
    exprn
        Expression to compute the ceil/floor of.

Return type:
    int
Error conditions:
    Returns bottom if exprn evaluates to bottom.

Examples:
Code:
1. value = ceil(5.5)
  Sets value to 6.
2. value = ceil(-2)
  Sets value to -2.
3. value=floor(5.5)
  Sets value to 5.

Additional Notes Provided by Ricepigeon:
Although it is not explicitly addressed in the docs, many people make the mistake of viewing the Floor and Ceil functions as equivalent to "Round Down" and "Round Up", respectively. While this is true for all values greater than or equal to 0, this does not hold true for values less than 0. For example;

Code:
value = ceil(-5.5)

In the above example, people might mistakenly expect value to be set to -6. However, since Ceil always returns the least integer greater than or equal to its argument, Ceil(-5.5) actually returns a value of -5. Thus, if one intends to use Ceil or Floor for the purposes of rounding or truncating floats into integers, one will have to make use of the IfElse or Cond functions in the following manner:

Code:
;Truncate decimal values and return only the integer value of X
value = ifelse(X>=0,Floor(X),Ceil(X))
Last Edit: September 29, 2015, 12:23:46 am by Just No Point

Bea

Re: Ceil (math) (Triggers)
#2  September 13, 2015, 01:13:59 am
  • *****
  • MUGEN Grandma
    • Brazil
    • www.smeenet.org
It can be used to build a round to integer function when used like this:

ceil(value - 0.5)

The inverse function, floor, can be used in the same fashion:

floor(value + 0.5)
Princess Adora: "My friend saw She-Ra take her dress off in the shower. She said she has an 8 pack. She said She-Ra is shredded."

SF2NES is dead. Long live SF2NES.
Re: Ceil (math) (Triggers)
#3  September 13, 2015, 09:26:26 am
  • ******
  • Hedgehog Whisperer
  • Red Bull addict
    • Spain
    • xgargoyle.mgbr.net
also, whenever you must perform a division with unknown or variable numbers, use always ceil() to prevent division by 0
XGargoyle: Battle posing since 1979
http://xgargoyle.mgbr.net
http://www.pandorabots.com/pandora/talk?botid=e71c0d43fe35093a  <-- Please click that link
http://paypal.me/XGargoyle  <-- Donations welcome!
Re: Ceil (math) (Triggers)
#4  September 13, 2015, 02:31:21 pm
  • ***
I got some questions.
What is the actual purpose ceil?
Is there a reason why I would replace this with any actual number?

I see some coders use it for damage or velocity.
Could variable values (i.e. LP, MP, HP variants) and damage dampners be the reasons for it?
Re: Ceil (math) (Triggers)
#5  September 13, 2015, 06:31:52 pm
  • ****
  • it's me
  • Bat's a Wrap.
    • Chile
    • koakoa@jabber.org
    • Skype - koakumadevil69
Some expressions are made so they exactly take integers only, and thus, there must be a way to convert floats (they look like decimals with up to 6 decimal digits of precision, e.g: 124.435692) to integers, ceil and floor both do this purpose but they handle it differently, ceil takes the closest integer that's larger than the float. floor takes the closest, lower integer to the float specified.

The most common use as you said, is for damage and damage dampeners.  In which there are cases you wouldn't want minimal proration damage to become zero if you used floor, it also maximizes damage done by the character by a few hit points in a combo while still having the effect of the dampener. And thus, you use ceil. (eg: damage = ceil(fvar(11)*10))

Other uses include being able to use triggers like screenpos, p2bodydist, p2dist, etc. as arguments for integer only parameters, by just simply writing ceil( trigger_name )

Also keep in mind that for negatives (I'm going to use -14.3 for example)
ceil(-14.3) = -14, because -14 is the closest largest integer to -14.3
Yeaaaah im shootign ducks wiht the paino
Last Edit: September 13, 2015, 06:35:19 pm by Daniel9999999
Re: Ceil (math) (Triggers)
#6  September 14, 2015, 11:11:55 am
  • ***
Thank you for the explanaition, your examples made it easier to understand :)
Ceil (math) and Floor (math) (Triggers)
#7  September 25, 2015, 05:11:57 pm
  • *****
  • Thanks and God bless
    • USA
    • ricepigeon.neocities.org
Implements the "ceiling" and "floor" functions, respectively. Ceil returns the least integer which is greater than or equal to the specified argument, while Floor returns the greatest integer less than or equal to its argument.

Format:
    1.) ceil(exprn)
    2.) floor(exprn)
Arguments:
    exprn
        Expression to compute the ceil/floor of.

Return type:
    int
Error conditions:
    Returns bottom if exprn evaluates to bottom.

Examples:
Code:
1. value = ceil(5.5)
  Sets value to 6.
2. value = ceil(-2)
  Sets value to -2.
3. value=floor(5.5)
  Sets value to 5.

Additional Notes:
Although it is not explicitly addressed in the docs, many people make the mistake of viewing the Floor and Ceil functions as equivalent to "Round Down" and "Round Up", respectively. While this is true for all values greater than or equal to 0, this does not hold true for values less than 0. For example;

Code:
value = ceil(-5.5)

In the above example, people might mistakenly expect value to be set to -6. However, since Ceil always returns the least integer greater than or equal to its argument, Ceil(-5.5) actually returns a value of -5. Thus, if one intends to use Ceil or Floor for the purposes of rounding or truncating floats into integers, one will have to make use of the IfElse or Cond functions in the following manner:

Code:
;Truncate decimal values and return only the integer value of X
value = ifelse(X>=0,Floor(X),Ceil(X))
Last Edit: September 25, 2015, 05:15:32 pm by Ricepigeon
Re: Ceil (math) and Floor (math) (Triggers)
New #8  September 27, 2015, 08:58:52 am
  • ****
  • Still lurks regularly, but posts once a blue moon
    • Canada
Additional Notes:
Although it is not explicitly addressed in the docs, many people make the mistake of viewing the Floor and Ceil functions as equivalent to "Round Down" and "Round Up", respectively. While this is true for all values greater than or equal to 0, this does not hold true for values less than 0. For example;

Code:
value = ceil(-5.5)

In the above example, people might mistakenly expect value to be set to -6. However, since Ceil always returns the least integer greater than or equal to its argument, Ceil(-5.5) actually returns a value of -5.

Isn't that technically the behavior of "Round Down" and "Round Up"?
If you round -5.5 upwards, you should get -5, not -6.  Because -5 > -6.
Therefore -5 is "up", -6 is "down".

They should be equivalent to the mathematical ceil and floor symbols:

https://www.mathsisfun.com/sets/function-floor-ceiling.html
Last Edit: September 29, 2015, 12:26:47 am by Just No Point