MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: SetPrecision causes logical comparisons to fail in Mathematica 5.1 on Mac OS X?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63986] Re: [mg63967] SetPrecision causes logical comparisons to fail in Mathematica 5.1 on Mac OS X?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Thu, 26 Jan 2006 03:43:17 -0500 (EST)
  • References: <200601251345.IAA25867@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 25 Jan 2006, at 14:45, jjdmon wrote:

> I am running Mathematica 5.1.1.0 on Mac OS 10.3.9 and have encountered
> what seems like a bug using SetPrecision to limit the significant
> places of real numbers.
>
> If I do this:
>
> In: x=SetPrecision[1.101,2]
> Out: 1.1
>
> I get this:
>
> In: x==0.0
> Out: True
>
> In: x==1.0
> Out: True
>
> Is this expected behavior?
>


It is a well known behaviour. It has come up here a number of times.  
A partial explanation is given in the documentation for Equal:

"Approximate numbers are considered equal if they differ in at most  
their last eight binary digits (roughly their last two decimal digits)."

The workaround is never to set anything to have so few digits of  
precision; there is no reason at all to do so. Mathematica's  
"significance" arithmetic is an approximation to true interval  
arithmetic that works well only at high precision.

If you only wanted to reduce the number of digits displayed you  
should use

NumberForm[1.101, 2]

Andrzej Kozlowski


  • Prev by Date: Re: SetPrecision causes logical comparisons to fail in Mathematica 5.1 on Mac OS X?
  • Next by Date: Re: Factorising polynomials
  • Previous by thread: Re: Re: SetPrecision causes logical comparisons to fail in Mathematica 5.1 on Mac OS X?
  • Next by thread: How to define a constant in mathematica like Pi