Assertions involving NaN

I use ounit to test the code of my lexer + parser. I have test input which should result in a NaN; I don’t know how to test this because NaN != NaN , so assert_equal will fail :frowning:


Ian

Try Float.is_nan. See OCaml library : Float.

1 Like

Thanks, that helped.

You can also use Float.compare x y = 0 instead of x = y. Float.compare compares NaNs equal and Nan and non-NaN different.

3 Likes