Re: Ceiling & Floor
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: Ceiling & Floor
- From: David Withoff <withoff>
- Date: Fri, 3 Apr 1992 18:07:16 -0600
John Gray writes: > The comments from Dave Withoff are useful, but still the following three > computations make one wonder what is really going on. > > In[19]:= Ceiling[10^22 + 0.] > > Out[19]= 10000000000000000000000 > > In[20]:= Ceiling[10^23 + 0.] > > Out[20]= 99999999999999991611392 > > In[21]:= Ceiling[10^23 + 0.000000000000000000000000000] > > Out[21]= 99999999999999991611392 > > One expects something to happen between 19 and 20 digits, but not between > 22 and 23 digits. All of the digits in Ceiling[<machine double>] beyond machine precision are ambiguous, and Ceiling returns garbage. The fact that the garbage digits cause Ceiling[10^22+0.] to return 10^22 is a coincidence. The Ceiling function simply provides a mapping from doubles to integers: . . 10.^22 - 1049089 ==> 9999999999999997902848 10.^22 - 1049088 ==> 10000000000000000000000 . . . 10.^22 + 1049088 ==> 10000000000000000000000 10.^22 + 1049089 ==> 10000000000000002097152 . . There is undoubtedly a pattern that would explain why certain numbers such as 10^22, 10^22 + 2097152, etc., map as expected, but there is otherwise nothing special about 10^22. There is a special number where Ceiling[<machine double>] can no longer give an unambiguous mathematical ceiling (a "correct" answer). On a SPARC, where machine doubles have a precision of 16, that number is 2^53, or about 10^16, as expected: In[288]:= Table[2^53+n-Ceiling[2^53+n+0.], {n, -5, 10}] Out[288]= {0, 0, 0, 0, 0, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0} The inputs 0. and 0.000000000000000000000000000 are interpreted as machine doubles, and integer+double gives a double, so Ceiling[10^22 + 0.] is essentially equivalent to Ceiling[10.^22]. Dave Withoff withoff at wri.com