mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Add stdlib functions from anselme v1
This commit is contained in:
parent
581c60048d
commit
dac5b74fa6
30 changed files with 272 additions and 14 deletions
|
|
@ -50,4 +50,20 @@ return {
|
|||
{ "rand", "(min::number, max::number)", function(state, min, max) return Number:new(math.random(min.number, max.number)) end },
|
||||
{ "rand", "(max::number)", function(state, max) return Number:new(math.random(max.number)) end },
|
||||
{ "rand", "()", function(state) return Number:new(math.random()) end },
|
||||
|
||||
{ "floor", "(x::number)", function(state, x) return Number:new(math.floor(x.number)) end },
|
||||
{ "ceil", "(x::number)", function(state, x) return Number:new(math.ceil(x.number)) end },
|
||||
{
|
||||
"round", "(x::number, increment=1)",
|
||||
function(state, x, increment)
|
||||
local n = x.number / increment.number
|
||||
if n >= 0 then
|
||||
return Number:new(math.floor(n + 0.5) * increment.number)
|
||||
else
|
||||
return Number:new(math.ceil(n - 0.5) * increment.number)
|
||||
end
|
||||
end
|
||||
},
|
||||
|
||||
{ "pi", Number:new(math.pi) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue