Commit a6c0459384a0899f5ca9c56e78c21f3f37b3af0a
1 parent
a43410e1
非法数字判断加强判断
Showing
1 changed file
with
18 additions
and
4 deletions
Show diff stats
src/utils/MathUtil.lua
| ... | ... | @@ -42,12 +42,26 @@ function math.randWeight(dataset, field) |
| 42 | 42 | end |
| 43 | 43 | |
| 44 | 44 | function math.illegalNum(num, min, max) |
| 45 | - local illegal = true | |
| 45 | + if type(num) ~= "number" then | |
| 46 | + -- 非数字类型 | |
| 47 | + return true | |
| 48 | + end | |
| 49 | + if num ~= num then | |
| 50 | + -- 非法数字nan | |
| 51 | + return true | |
| 52 | + end | |
| 53 | + if num ~= math.floor(num) then | |
| 54 | + -- 非整数 | |
| 55 | + return true | |
| 56 | + end | |
| 57 | + if math.abs(max - min) > 1000 then | |
| 58 | + -- 防止出现数值过大的情况,在线上环境出现效率问题 | |
| 59 | + return true | |
| 60 | + end | |
| 46 | 61 | for i = min, max do |
| 47 | 62 | if num == i then |
| 48 | - illegal = false | |
| 49 | - break | |
| 63 | + return false | |
| 50 | 64 | end |
| 51 | 65 | end |
| 52 | - return illegal | |
| 66 | + return true | |
| 53 | 67 | end |
| 54 | 68 | \ No newline at end of file | ... | ... |