From savicky at cs.cas.cz  Thu Apr 23 10:21:45 2009
From: savicky at cs.cas.cz (Petr Savicky)
Date: Thu, 23 Apr 2009 10:21:45 +0200
Subject: [Rd] 'is.integer' (PR#13671)
In-Reply-To: <8b356f880904221330r2c2776cid12036442511b216@mail.gmail.com>
References: <20090422174516.2EB1928321BF@mail.pubhealth.ku.dk>
	<8b356f880904221330r2c2776cid12036442511b216@mail.gmail.com>
Message-ID: <20090423082145.GA31740@cs.cas.cz>

On Wed, Apr 22, 2009 at 04:30:36PM -0400, Stavros Macrakis wrote:
[snip]
> Now consider 1e40, which has the property
> that floor(x)==x==ceiling(x), which you might think characterizes an
> integer;  but it also has the property that x+1 == x.  Similarly for
> 1/3 * 1e40.
[snip]

The number 1/3 * 1e40 is larger than 2^53 and every value of double type,
which is larger than 2^53, is an even integer. The number has at least 54
digits mathematically, but only the first 53 of them are stored, so the last
one is zero. Since rounding is done towards an even value, we get x+1 == x.

Double type is safe for integer values in the interval [-2^53, 2^53].
Inside this interval, basic arithmetic operations (+,-,*,/) on integers,
whose result is an integer mathematically, yield integer result also in
the machine.

Petr.



[Rd] 'is.integer' (PR#13671)
Petr Savicky