Module std.math
Additions to the core math module.
The module table returned by std.math also contains all of the entries from
the core math table. An hygienic way to import this module, then, is simply
to override the core math locally:
local math = require 'std.math'
Core Functions
| floor (n[, p=0]) | Extend math.floor to take the number of decimal places. |
| round (n[, p=0]) | Round a number to a given number of decimal places. |
Deprecated Functions
| monkey_patch ([namespace=_G]) | Overwrite core math methods with std enhanced versions. |
Core Functions
- floor (n[, p=0])
-
Extend
math.floorto take the number of decimal places.Parameters:
- n number number
- p integer number of decimal places to truncate to (default 0)
Returns:
-
number
ntruncated topdecimal placesUsage:
tenths = floor(magnitude, 1)
- round (n[, p=0])
-
Round a number to a given number of decimal places.
Parameters:
- n number number
- p integer number of decimal places to round to (default 0)
Returns:
-
number
nrounded topdecimal placesUsage:
roughly = round(exactly, 2)