Surviving Mars

Surviving Mars

评价数不足
math. Functions
   
奖励
收藏
已收藏
取消收藏
文件大小
发表于
更新日期
10.126 KB
2018 年 7 月 16 日 下午 7:17
2022 年 9 月 22 日 下午 4:57
16 项改动说明 ( 查看 )

订阅以下载
math. Functions

在 ChoGGi 的 1 个合集中
ChoGGi's Mods: Modding
17 件物品
描述
Modders only (unless it's a mod that uses these functions).

For some reason SM doesn't have any of lua "math." functions.
Functions are either from SM (math.min = Min()), or pure lua.

SM and certain SM functions have issues with floats: 5 == 5.5 returns true for one (though 5.0 == 5.5 returns false).
Which is why I'm not just using math.cos = cos... (you can access them as math.sm_cos)
I'm going for accuracy not speed: Bench with GetPreciseTicks()

Implemented:
abs, ceil, deg, exp, floor, fmod, huge, log, max, maxinteger, min, mininteger, modf, pi, rad, random, randomseed, sqrt, tointeger, type, ult

Not implemented yet:
cos, sin, tan, acos, asin, atan


I'm only implementing the ones listed in the manual, if you have some to add: feel free to send them to me.

Functions should return values according to:
https://www.lua.org/manual/5.3/manual.html#6.7
You can test results with a copy of lua.exe: https://github.com/HazeProductions/Lua-x64.
If the result it gives is different then my func: Please let me know.
8 条留言
Unichi 2018 年 8 月 21 日 下午 12:23 
I looked here:
https://www.gammon.com.au/scripts/doc.php?lua=math.random

It states "That is, zero up to but excluding 1", which makes sense, it's like that in most random() functions :)
ChoGGi  [作者] 2018 年 8 月 21 日 下午 12:19 
Oh, I was just going by https://www.lua.org/manual/5.3/manual.html#pdf-math.random

When called without arguments, returns a pseudo-random float with uniform distribution in the range [0,1).[/i]
I suppose that wouldn't be a 1 ever... whoops
Unichi 2018 年 8 月 21 日 下午 12:02 
Hey, based on the documentation of math.random for Lua it never includes 1 by design. I found this because it works the same way in JavaScript (and in ANSI-C, afaik, for that matter)

It's basically to make

SomeTable[math.floor(math.random() * #SomeTable)]

work as expected without subtracting 1 from the count (it will never yield an invalid index, as you never reach #SomeTable, only just _before_ #SomeTable which will floor to #SomeTable - 1

I wouldn't include this as a "Known Issue", this is actually correct (and right/good) behavior :)
ChoGGi  [作者] 2018 年 7 月 29 日 下午 10:23 
v0.4
Changed:
.log(number,NaN) would assume NaN was Napier's constant, now it errors out.
.maxinteger/.mininteger now use max_int/min_int instead of the values from lua console.

Fixed:
.ceil() was off for negative numbers with a few decimal place digits.
ChoGGi  [作者] 2018 年 7 月 18 日 下午 2:07 
v0.3
Fixed: math.fmod, math.modf, math.log, math.random(n).
More unit testing.
Removed lua.exe, use https://github.com/HazeProductions/Lua-x64 .
Dash 2018 年 7 月 18 日 上午 2:11 
Thank you for this library!
ChoGGi  [作者] 2018 年 7 月 17 日 下午 6:14 
Aww, thanks

I didn't really expect this to be popular, but I'm sure some people will enjoy it :)
SkiRich 2018 年 7 月 17 日 下午 5:51 
Subscriber #1. Because I know.