Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point precision error #15

Closed
ghost opened this issue Jun 18, 2012 · 1 comment · Fixed by #30
Closed

Floating point precision error #15

ghost opened this issue Jun 18, 2012 · 1 comment · Fixed by #30

Comments

@ghost
Copy link

ghost commented Jun 18, 2012

math.huge does not unpack to the same value (in my machine, it in fact unpacks to a negative number).

@ghost
Copy link
Author

ghost commented Jun 18, 2012

I found what the issue was, it wasn't a precision error at all. You were deciding whether a lua_Number n represented a floating point value (float/double) instead of an integer through the comparison floor(n) != n. This fails when n is +-inf, since then floor(n) == n. When n is NaN, this also fails, since even tough floor(n) will return n, NaN fails to compare equal to any number, even itself. Your method also has the issue of not checking whether the floating point value could actually be represented by an int64_t, if it is integral in value.

I'm making a fork of the project, intending to send a pull request later.

@ghost ghost mentioned this issue Jun 18, 2012
mattsta added a commit to mattsta/lua-cmsgpack that referenced this issue Apr 7, 2014
Changes:
  - Improve table vs. array detection
  - Improve packing +-inf
  - Add multiple pack/unpack support
  - Add cmsgpack.safe module variant
  - Add local build infrastructure for easier testing
  - Add user-controlled unpack support limiting returned objects
  - Add Lua 5.3 compatibility
  - Remove an unnecessary malloc
  - Use Lua memory allocator instead of malloc for buffer creation

Issues involved:
  - closes antirez#16 - allow multi pack/unpack by default
  - closes antirez#10 - unpack one/limit API added
  - closes antirez#13 and closes antirez#20 - use Lua allocator
  - closes antirez#15 - (included in antirez#16)
  - ignores antirez#22 because it's confusing
  - closes antirez#23 - fixed elsewhere
  - closes antirez#26 - extracted some useful parts from a difficult commit
  - closes antirez#28 - we started tagging versions again recently
  - closes antirez#27 - that failure case works for me now

I merged commits with original author information where possible, but
each commit required manual cleanup of one or more of:
formatting fixes (no tabs, please), commit message fixes (more details
please), extracting contents from a single 300 line commit with 5
different logical changes merged together, and general correctness
checking after merging with newer code.

As of this commit, all tests pass on Lua 5.1.5 and Lua 5.3-work2.
mattsta added a commit to mattsta/lua-cmsgpack that referenced this issue Apr 7, 2014
Changes:
  - Improve table vs. array detection
  - Improve packing +-inf
  - Add multiple pack/unpack support
  - Add cmsgpack.safe module variant
  - Add local build infrastructure for easier testing
  - Add user-controlled unpack support limiting returned objects
  - Add Lua 5.3 compatibility
  - Remove an unnecessary malloc
  - Use Lua memory allocator instead of malloc for buffer creation

Issues involved:
  - closes antirez#16 - allow multi pack/unpack by default
  - closes antirez#10 - unpack one/limit API added
  - closes antirez#13 and closes antirez#20 - use Lua allocator
  - closes antirez#15 - (included in antirez#16)
  - ignores antirez#22 because it's confusing
  - closes antirez#23 - fixed elsewhere
  - closes antirez#26 - extracted some useful parts from a difficult commit
  - closes antirez#28 - we started tagging versions again recently
  - closes antirez#27 - that failure case works for me now

I merged commits with original author information where possible, but
each commit required manual cleanup of one or more of:
formatting fixes (no tabs, please), commit message fixes (more details
please), extracting contents from a single 300 line commit with 5
different logical changes merged together, and general correctness
checking after merging with newer code.

As of this commit, all tests pass on Lua 5.1.5 and Lua 5.3-work2.
mattsta added a commit to mattsta/lua-cmsgpack that referenced this issue Apr 7, 2014
Changes:
  - Improve table vs. array detection
  - Improve packing +-inf
  - Add multiple pack/unpack support
  - Add cmsgpack.safe module variant
  - Add local build infrastructure for easier testing
  - Add user-controlled unpack support limiting returned objects
  - Add Lua 5.3 compatibility
  - Remove an unnecessary malloc
  - Use Lua memory allocator instead of malloc for buffer creation

Issues involved:
  - closes antirez#16 - allow multi pack/unpack by default
  - closes antirez#10 - unpack one/limit API added
  - closes antirez#13 and closes antirez#20 - use Lua allocator
  - closes antirez#15 - (included in antirez#16)
  - ignores antirez#22 because it's confusing
  - closes antirez#23 - fixed elsewhere
  - closes antirez#26 - extracted some useful parts from a difficult commit
  - closes antirez#28 - we started tagging versions again recently
  - closes antirez#27 - that failure case works for me now

I merged commits with original author information where possible, but
each commit required manual cleanup of one or more of:
formatting fixes (no tabs, please), commit message fixes (more details
please), extracting contents from a single 300 line commit with 5
different logical changes merged together, and general correctness
checking after merging with newer code.

As of this commit, all tests pass on Lua 5.1.5 and Lua 5.3-work2.
mattsta added a commit to mattsta/lua-cmsgpack that referenced this issue Apr 7, 2014
Changes:
  - Improve table vs. array detection
  - Improve packing +-inf
  - Add multiple pack/unpack support
  - Add cmsgpack.safe module variant
  - Add local build infrastructure for easier testing
  - Add user-controlled unpack support limiting returned objects
  - Add Lua 5.3 compatibility
  - Remove an unnecessary malloc
  - Use Lua memory allocator instead of malloc for buffer creation

Issues involved:
  - closes antirez#16 - allow multi pack/unpack by default
  - closes antirez#10 - unpack one/limit API added
  - closes antirez#13 and closes antirez#20 - use Lua allocator
  - closes antirez#15 - (included in antirez#16)
  - ignores antirez#22 because it's confusing
  - closes antirez#23 - fixed elsewhere
  - closes antirez#26 - extracted some useful parts from a difficult commit
  - closes antirez#28 - we started tagging versions again recently
  - closes antirez#27 - that failure case works for me now

I merged commits with original author information where possible, but
each commit required manual cleanup of one or more of:
formatting fixes (no tabs, please), commit message fixes (more details
please), extracting contents from a single 300 line commit with 5
different logical changes merged together, and general correctness
checking after merging with newer code.

As of this commit, all tests pass on Lua 5.1.5 and Lua 5.3-work2.
mattsta added a commit to mattsta/lua-cmsgpack that referenced this issue Apr 7, 2014
Changes:
  - Improve table vs. array detection
  - Improve packing +-inf
  - Add multiple pack/unpack support
  - Add cmsgpack.safe module variant
  - Add local build infrastructure for easier testing
  - Add user-controlled unpack support limiting returned objects
  - Add Lua 5.3 compatibility
  - Remove an unnecessary malloc
  - Use Lua memory allocator instead of malloc for buffer creation

Issues involved:
  - closes antirez#16 - allow multi pack/unpack by default
  - closes antirez#10 - unpack one/limit API added
  - closes antirez#13 and closes antirez#20 - use Lua allocator
  - closes antirez#15 - (included in antirez#16)
  - ignores antirez#22 because it's confusing
  - closes antirez#23 - fixed elsewhere
  - closes antirez#26 - extracted some useful parts from a difficult commit
  - closes antirez#28 - we started tagging versions again recently
  - closes antirez#27 - that failure case works for me now

I merged commits with original author information where possible, but
each commit required manual cleanup of one or more of:
formatting fixes (no tabs, please), commit message fixes (more details
please), extracting contents from a single 300 line commit with 5
different logical changes merged together, and general correctness
checking after merging with newer code.

As of this commit, all tests pass on Lua 5.1.5 and Lua 5.3-work2.
mattsta added a commit to mattsta/lua-cmsgpack that referenced this issue Apr 7, 2014
Changes:
  - Improve table vs. array detection
  - Improve packing +-inf
  - Add multiple pack/unpack support
  - Add cmsgpack.safe module variant
  - Add local build infrastructure for easier testing
  - Add user-controlled unpack support limiting returned objects
  - Add Lua 5.3 compatibility
  - Remove an unnecessary malloc
  - Use Lua memory allocator instead of malloc for buffer creation

Issues involved:
  - closes antirez#16 - allow multi pack/unpack by default
  - closes antirez#10 - unpack one/limit API added
  - closes antirez#13 and closes antirez#20 - use Lua allocator
  - closes antirez#15 - (included in antirez#16)
  - ignores antirez#22 because it's confusing
  - closes antirez#23 - fixed elsewhere
  - closes antirez#26 - extracted some useful parts from a difficult commit
  - closes antirez#28 - we started tagging versions again recently
  - closes antirez#27 - that failure case works for me now

I merged commits with original author information where possible, but
each commit required manual cleanup of one or more of:
formatting fixes (no tabs, please), commit message fixes (more details
please), extracting contents from a single 300 line commit with 5
different logical changes merged together, and general correctness
checking after merging with newer code.

As of this commit, all tests pass on Lua 5.1.5 and Lua 5.3-work2.
mattsta added a commit to mattsta/lua-cmsgpack that referenced this issue Apr 7, 2014
Changes:
  - Improve table vs. array detection
  - Improve packing +-inf
  - Add multiple pack/unpack support
  - Add cmsgpack.safe module variant
  - Add local build infrastructure for easier testing
  - Add user-controlled unpack support limiting returned objects
  - Add Lua 5.3 compatibility
  - Remove an unnecessary malloc
  - Use Lua memory allocator instead of malloc for buffer creation

Issues involved:
  - closes antirez#16 - allow multi pack/unpack by default
  - closes antirez#10 - unpack one/limit API added
  - closes antirez#13 and closes antirez#20 - use Lua allocator
  - closes antirez#15 - (included in antirez#16)
  - ignores antirez#22 because it's confusing
  - closes antirez#23 - fixed elsewhere
  - closes antirez#26 - extracted some useful parts from a difficult commit
  - closes antirez#28 - we started tagging versions again recently
  - closes antirez#27 - that failure case works for me now

I merged commits with original author information where possible, but
each commit required manual cleanup of one or more of:
formatting fixes (no tabs, please), commit message fixes (more details
please), extracting contents from a single 300 line commit with 5
different logical changes merged together, and general correctness
checking after merging with newer code.

As of this commit, all tests pass on Lua 5.1.5 and Lua 5.3-work2.
mattsta added a commit to mattsta/lua-cmsgpack that referenced this issue Apr 11, 2014
Changes:
  - Improve table vs. array detection
  - Improve packing +-inf
  - Add multiple pack/unpack support
  - Add cmsgpack.safe module variant
  - Add local build infrastructure for easier testing
  - Add user-controlled unpack support limiting returned objects
  - Add Lua 5.3 compatibility
  - Remove an unnecessary malloc
  - Use Lua memory allocator instead of malloc for buffer creation

Issues involved:
  - closes antirez#16 - allow multi pack/unpack by default
  - closes antirez#10 - unpack one/limit API added
  - closes antirez#13 and closes antirez#20 - use Lua allocator
  - closes antirez#15 - (included in antirez#16)
  - ignores antirez#22 because it's confusing
  - closes antirez#23 - fixed elsewhere
  - closes antirez#26 - extracted some useful parts from a difficult commit
  - closes antirez#28 - we started tagging versions again recently
  - closes antirez#27 - that failure case works for me now

I merged commits with original author information where possible, but
each commit required manual cleanup of one or more of:
formatting fixes (no tabs, please), commit message fixes (more details
please), extracting contents from a single 300 line commit with 5
different logical changes merged together, and general correctness
checking after merging with newer code.

As of this commit, all tests pass on Lua 5.1.5 and Lua 5.3-work2.
mattsta added a commit to mattsta/lua-cmsgpack that referenced this issue Apr 11, 2014
Changes:
  - Improve table vs. array detection
  - Improve packing +-inf
  - Add multiple pack/unpack support
  - Add cmsgpack.safe module variant
  - Add local build infrastructure for easier testing
  - Add user-controlled unpack support limiting returned objects
  - Add Lua 5.3 compatibility
  - Remove an unnecessary malloc
  - Use Lua memory allocator instead of malloc for buffer creation

Issues involved:
  - closes antirez#16 - allow multi pack/unpack by default
  - closes antirez#10 - unpack one/limit API added
  - closes antirez#13 and closes antirez#20 - use Lua allocator
  - closes antirez#15 - (included in antirez#16)
  - ignores antirez#22 because it's confusing
  - closes antirez#23 - fixed elsewhere
  - closes antirez#26 - extracted some useful parts from a difficult commit
  - closes antirez#28 - we started tagging versions again recently
  - closes antirez#27 - that failure case works for me now
  - closes antirez#31 - fix comment typos

I merged commits with original author information where possible, but
each commit required manual cleanup of one or more of:
formatting fixes (no tabs, please), commit message fixes (more details
please), extracting contents from a single 300 line commit with 5
different logical changes merged together, and general correctness
checking after merging with newer code.

As of this commit, all tests pass on Lua 5.1.5 and Lua 5.3-work2.
mattsta added a commit to mattsta/lua-cmsgpack that referenced this issue Apr 14, 2014
Changes:
  - Improve table vs. array detection
  - Improve packing +-inf
  - Add multiple pack/unpack support
  - Add cmsgpack.safe module variant
  - Add local build infrastructure for easier testing
  - Add user-controlled unpack support limiting returned objects
  - Add Lua 5.3 compatibility
  - Remove an unnecessary malloc
  - Use Lua memory allocator instead of malloc for buffer creation

Issues involved:
  - closes antirez#16 - allow multi pack/unpack by default
  - closes antirez#10 - unpack one/limit API added
  - closes antirez#13 and closes antirez#20 - use Lua allocator
  - closes antirez#15 - (included in antirez#16)
  - ignores antirez#22 because it's confusing
  - closes antirez#23 - fixed elsewhere
  - closes antirez#26 - extracted some useful parts from a difficult commit
  - closes antirez#28 - we started tagging versions again recently
  - closes antirez#27 - that failure case works for me now
  - closes antirez#31 - fix comment typos

I merged commits with original author information where possible, but
each commit required manual cleanup of one or more of:
formatting fixes (no tabs, please), commit message fixes (more details
please), extracting contents from a single 300 line commit with 5
different logical changes merged together, and general correctness
checking after merging with newer code.

As of this commit, all tests pass on Lua 5.1.5 and Lua 5.3-work2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

0 participants