lunarmodules / luassert

Assertion library for Lua
MIT License
202 stars 77 forks source link

Compare NaN values equal #130

Closed ZyX-I closed 7 years ago

ZyX-I commented 9 years ago

Fixes Olivine-Labs/busted#453.

ZyX-I commented 9 years ago

LuaJIT succeeds and gets SEGV at exit.

o-lim commented 9 years ago

is_same is more analogous to == in C/C++. There really is no analog to memcmp in lua, besides you wouldn't really use memcmp to compare two C++ objects for equality (i.e. memcmp does not perform a deep compare). You would have the same problem if you were to attempt the same comparison in C/C++ or any programming language, it would also perform a floating-point compare for NaN values nested inside a container.

In your case it may be better to create a special table that represents NaN instead. Replacing numeric NaN with table NaN where appropriate or wrapping your function that may return NaN to return table NaN.

ZyX-I commented 9 years ago

@o-lim In C == does not perform deep comparison either like it does here. Not sure about C++, but I guess it will not without overriding ==. Also note that e.g. authors of numpy know that tests that compare NaN equal are needed: numpy.testing.assert_array_equal (numpy.testing.assert_equal also has this property, but it is not expressed in documentation).

As the alternative it makes sense to either have different is_same version or an optional argument to is_same that makes it compare NaN values equal.


In any case first it is needed to report luajit crash. I do not yet have minimal working example, but can say that:

  1. Removing NaN inside table test makes tests no longer crash.
  2. Running only new tests using --filter=NaN does not make luajit crash. Including running only table test that is required to crash the test suite.
DorianGray commented 8 years ago

Any updates here?