Difference between revisions of "Floor - Math"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>JustinOther
m (→‎Examples: Example assumed Math had been imported)
imported>FrankFamily
Line 21: Line 21:
int x = Math.Floor(2.1) ; x == 2
int x = Math.Floor(2.1) ; x == 2
int y = Math.Floor(5.9) ; y == 5
int y = Math.Floor(5.9) ; y == 5
int z = Math.Floor(-0.7) ; z == -1
</source>
</source>


== Notes ==
== Notes ==
*Casting a Float to an Int verifiably produces the same results and is measurably faster.
*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.


== See Also ==
== See Also ==
*[[Math Script]]
*[[Math Script]]
*[[Ceiling - Math]]
*[[Ceiling - Math]]

Revision as of 20:38, 3 October 2016

Member of: Math Script

Calculates the largest integer less than or equal to the passed in value.

Syntax

int Function Floor(float afValue) native global

Parameters

  • afValue: The value to get the floor of.

Return Value

The floor of the passed-in value.

Examples

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

  • 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.

See Also