In working on developing unit tests for my GF4 project, I'm going to have to compare expected vs actual results of floating point numbers. This subject is notoriously difficult to get "right" - there are all kinds of pitfalls one would never think about. The standard Python library now has one test for this - math.isclose().
I just learned that pytest provides such a test, packaged up for unit testing.. Here is an example: import pytest PRECISION = 1e-3 def assert_almost_equal(): obtained_value = 99.99 expected_value = 100.00 assert obtained_value == pytest.approx(expected_value, PRECISION) See What is the best way to compare floats for almost-equality in Python? <https://stackoverflow.com/questions/5595425/what-is-the-best-way-to-compare-floats-for-almost-equality-in-python> -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/85cdc9ed-30d5-44a5-9115-d6102d5d5571n%40googlegroups.com.