Re: inconsistency with Inequality testing and Floor
- To: mathgroup at smc.vnet.net
- Subject: [mg59983] Re: inconsistency with Inequality testing and Floor
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sat, 27 Aug 2005 04:11:12 -0400 (EDT)
- Organization: The Open University, Milton Keynes, U.K.
- References: <dek8a1$aao$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Brett Patterson wrote: > I have observed the following strange behaviour: > > ---------------------- > In[1]:= x = 1.0 - 10^-($MachinePrecision) > > Out[1]= 1. > > In[2]:= x >= 1 > > Out[2]= True > > In[3]:= Floor[x] > > Out[3]= 0 > ---------------------- > > It seems that the inequality test and Floor use different numerical > methods. > I think this behaviour is inconsistent. > If the test "x >= 1" evaluates to True, then Floor[x] should evaluate > to 1. > > Can anyone shed any light on this? > > Regards, > Brett Patterson > > School of Physics, University of Western Australia; and > Institute of Photonics, University of Strathclyde, Scotland > Hi Brett, Looking at the value returned for x in *InputForm*, one can see that x is coded as 0.99999... indeed. This value is interpreted as 1.0 by function such as greater or equal to. However, according to the documentation, *Floor* uses different or additional numerical algorithms to establish its results that not only take in account $MachinePrecision but also $MaxExtraPrecision. One recommendation is to set the variable $MaxExtraPrecision to a higher value (see below). In[1]:= $MachinePrecision Out[1]= 15.954589770191003 In[2]:= x = 1. - 10^(-$MachinePrecision) Out[2]= 0.9999999999999999 In[3]:= x >= 1 Out[3]= True In[4]:= Floor[x] Out[4]= 0 In[5]:= Block[{$MaxExtraPrecision = 1000}, Floor[x]] Out[5]= 0 Best regards, /J.M.