This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients mark.dickinson, martin.panter, ned.deily, rhettinger, steven.daprano, tim.peters, vstinner
Date 2016-08-17.08:56:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1471424202.01.0.281682881857.issue27761@psf.upfronthosting.co.za>
In-reply-to
Content
Just to share my little experience with rounding numbers.

Last years, I worked on a API to convert timestamps between float and integers, the private "PyTime C API":

   https://haypo.github.io/pytime.html

At the beginning, I used various floatting point numbers which looks fine in decimal. But quickly, I got rounding issues on various buildbots. After many years fighting against compilers and trying to write a complete test suite, I decided to only use numbers which can be stored exactly in IEEE 754:

        if use_float:
            # numbers with an exact representation in IEEE 754 (base 2)
            for pow2 in (3, 7, 10, 15):
                ns = 2.0 ** (-pow2)
                ns_timestamps.extend((-ns, ns))

If you are curious, look at CPyTimeTestCase, TestCPyTime and TestOldPyTime classes in Lib/test/test_time.py.

At the end, I decided to reimplement each conversion function in pure Python using decimal.Decimal and compare the result with the C implementation. It makes the unit tests shorter and simpler.
History
Date User Action Args
2016-08-17 08:56:42vstinnersetrecipients: + vstinner, tim.peters, rhettinger, mark.dickinson, ned.deily, steven.daprano, martin.panter
2016-08-17 08:56:42vstinnersetmessageid: <1471424202.01.0.281682881857.issue27761@psf.upfronthosting.co.za>
2016-08-17 08:56:41vstinnerlinkissue27761 messages
2016-08-17 08:56:41vstinnercreate