Skip to content

Commit

Permalink
fix: be correct so we don't burn from Zs (#77)
Browse files Browse the repository at this point in the history
* fix: be correct so we don't burn from Zs

* fix: remove comment

* fix: saturate instead of wrap

* Revert "fix: saturate instead of wrap"

This reverts commit d407e53.

* fix: remember the sign
  • Loading branch information
Jengamon authored Jun 23, 2024
1 parent fcafc93 commit d05286a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/stdlib/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ pub fn load_base<'gc>(ctx: Context<'gc>) {
}
})
.try_fold(0i64, |acc, v| match v {
Some(v) if v < base => Some(acc * base + v),
Some(v) if v < base => Some(acc.wrapping_mul(base).wrapping_add(v)),
_ => None,
})
.map(|v| v * sign);
.map(|v| v.wrapping_mul(sign));
stack.replace(ctx, result.map(Value::Integer).unwrap_or(Value::Nil));
}

Expand Down
2 changes: 2 additions & 0 deletions tests/scripts/tonumber.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ do
assert(tonumber("1 1") == nil)
assert(tonumber({}) == nil)
assert(tonumber(nil) == nil)
assert(tonumber("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ", 36) == -1)
assert(tonumber("-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZAZZ", 36) == 32401)
assert(tonumber("-3.51234567e7") == -35123456.7)
assert(is_err(function() tonumber(3, 4) end))
assert(is_err(function() tonumber(3., 4) end))
Expand Down

0 comments on commit d05286a

Please sign in to comment.