Difference between revisions of "Floor - Math"
Jump to navigation
Jump to search
imported>Jlundin (New page: Category:Scripting Category:Papyrus '''Member of:''' Math Script Calculates the largest integer less than or equal to the passed in value. == Syntax == <source lang="papyrus"...) |
imported>FrankFamily |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:Scripting]] | [[Category:Scripting]] | ||
[[Category:Papyrus]] | [[Category:Papyrus]] | ||
[[Category:Non-delayed Native Function]] | |||
'''Member of:''' [[Math Script]] | '''Member of:''' [[Math Script]] | ||
Line 18: | Line 19: | ||
== Examples == | == Examples == | ||
<source lang="papyrus"> | <source lang="papyrus"> | ||
int x = Floor(2.1) ; x == 2 | int x = Math.Floor(2.1) ; x == 2 | ||
int y = Floor(5.9) ; y == 5 | int y = Math.Floor(5.9) ; y == 5 | ||
int z = Math.Floor(-0.7) ; z == -1 | |||
</source> | </source> | ||
== Notes == | |||
*Casting a Float to an Int verifiably produces the same results for positive numbers and is measurably faster. Results with negative numbers differs since casting truncates the number going towards 0 while floor gets the closest lower integer, therefore going towards negative infinite. | |||
<source lang="papyrus"> | |||
int floored = Math.Floor(-0.7) ; result is -1 | |||
int casted = -0.7 as int ; result is 0 | |||
</source> | |||
== See Also == | == See Also == | ||
*[[Math Script]] | *[[Math Script]] | ||
*[[Ceiling - Math]] | *[[Ceiling - Math]] |
Latest revision as of 20:40, 3 October 2016
Member of: Math Script
Calculates the largest integer less than or equal to the passed in value.
Syntax[edit | edit source]
int Function Floor(float afValue) native global
Parameters[edit | edit source]
- afValue: The value to get the floor of.
Return Value[edit | edit source]
The floor of the passed-in value.
Examples[edit | edit source]
int x = Math.Floor(2.1) ; x == 2
int y = Math.Floor(5.9) ; y == 5
int z = Math.Floor(-0.7) ; z == -1
Notes[edit | edit source]
- Casting a Float to an Int verifiably produces the same results for positive numbers and is measurably faster. Results with negative numbers differs since casting truncates the number going towards 0 while floor gets the closest lower integer, therefore going towards negative infinite.
int floored = Math.Floor(-0.7) ; result is -1
int casted = -0.7 as int ; result is 0