Skip to content

Commit

Permalink
Handle nan and inf in von (#3170)
Browse files Browse the repository at this point in the history
* Handle nan and inf in von

* Minor optimization
Add case for "nan" being interpreted as "n" followed by "an"

* Update lua/wire/von.lua

Co-authored-by: thegrb93 <[email protected]>

---------

Co-authored-by: thegrb93 <[email protected]>
  • Loading branch information
Denneisk and thegrb93 authored Nov 8, 2024
1 parent 5f704a2 commit b541f31
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lua/wire/von.lua
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,15 @@ _deserialize = {
a = find(s, "[;:}~]", i)

if a then
return tonumber(sub(s, i, a - 1)) or error("vON: Number definition does not contain a valid number!"), a - 1
a = a - 1
local c = sub(s, i, a)

return tonumber(c) or
(c == "inf" and math.huge) or
(c == "-inf" and -math.huge) or
((c == "nan" or c == "an") and 0/0) or
error("vON: Number definition does not contain a valid number!"),
a
end

-- Using %D breaks identification of negative numbers. :(
Expand Down

0 comments on commit b541f31

Please sign in to comment.