Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)]
Ben Bacarisse
ben.usenet at bsb.me.uk
Fri Jul 22 12:14:22 EDT 2016
Chris Kaynor <ckaynor at zindagigames.com> writes:
> On Thu, Jul 21, 2016 at 4:54 PM, Ben Bacarisse <ben.usenet at bsb.me.uk> wrote:
>
>> Steven D'Aprano <steve at pearwood.info> writes:
>> <snip>
>> > Or you might be using a language like Javascript, which intentionally has
>> > only floats for numbers. That's okay, you can still perform exact integer
>> > arithmetic, so long as you stay within the bounds of ±2**16.
>>
>> Small point: it's 2**52.
>>
>
> If you really want to be picky, it is 2**53, inclusive:
Yes, I mis-typed. Typical, I suppose, for a correction!
To add something useful, there are properties Number.MAX_SAFE_INTEGER
and Number.MIN_SAFE_INTEGER which are 2**53 - 1 and -2**53 + 1. These
are the largest (and smallest) integers such that i and i+1 (or i and
i-1) are exactly representable.
<snip>
--
Ben.
More information about the Python-list
mailing list