Various helpful mathematical functions
This module includes, and is a superset of the built-in Lua math
library so it is safe to do something like the following in your own code and still have access to both libraries:
local math = require("hs.math")
local n = math.sin(math.minFloat) -- works even though they're both from different libraries
The documentation for the math library can be found at http://www.lua.org/manual/5.3/ or from the Hammerspoon console via the help command: help.lua.math
. This includes the following functions and variables:
help.lua.math.abs
help.lua.math.acos
help.lua.math.asin
help.lua.math.atan
help.lua.math.ceil
help.lua.math.cos
help.lua.math.deg
help.lua.math.exp
help.lua.math.floor
help.lua.math.fmod
help.lua.math.huge
help.lua.math.log
help.lua.math.max
help.lua.math.maxinteger
help.lua.math.min
help.lua.math.mininteger
help.lua.math.modf
help.lua.math.pi
help.lua.math.rad
help.lua.math.random
help.lua.math.randomseed
help.lua.math.sin
help.lua.math.sqrt
help.lua.math.tan
help.lua.math.tointeger
help.lua.math.type
help.lua.math.ult
Additional functions and values that are specific to Hammerspoon which provide expanded math support are documented here.
Signature | hs.math.minFloat |
---|---|
Type | Constant |
Description | Smallest positive floating point number representable in Hammerspoon |
Notes |
|
Source | extensions/math/math.lua line 96 |
Signature | hs.math.isFinite(value) -> boolean |
---|---|
Type | Function |
Description | Returns whether or not the value is a finite number |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/math/math.lua line 78 |
Signature | hs.math.isInfinite(value) -> 1, -1, false |
---|---|
Type | Function |
Description | Returns whether or not the value is the mathematical equivalent of either positive or negative "Infinity" |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/math/math.lua line 61 |
Signature | hs.math.isNaN(value) -> boolean |
---|---|
Type | Function |
Description | Returns whether or not the value is the mathematical equivalent of "Not-A-Number" |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/math/math.lua line 44 |
Signature | hs.math.randomFloat() -> number |
---|---|
Type | Function |
Description | Returns a random floating point number between 0 and 1 |
Parameters |
|
Returns |
|
Source | extensions/math/libmath.m line 6 |
Signature | hs.math.randomFromRange(start, end) -> integer |
---|---|
Type | Function |
Description | Returns a random integer between the start and end parameters |
Parameters |
|
Returns |
|
Source | extensions/math/libmath.m line 26 |