MathGroup Archive 2003

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

Search the Archive

Re: Mod bug

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42873] Re: Mod bug
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Thu, 31 Jul 2003 01:47:57 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 7/30/03 at 4:07 AM, frauendorfer at perseus.fho-emden.de (frauendorfer) wrote:

> A program written in version 3 using Mod  fails completely in version
> 4.2 and 5.

> Checking Mod  I found a quite erratic behavior.For example Mod[.5,.1]
> gives the result 0.1.

The problem is you are working with machine precision numbers and not exact numbers. The mod function does not round numbers but works with precision given. One tenth does not have a finite binary expansion. Consequently, the nearest machine number is slightly different than one tenth. As a consequence, the Mod function returns a value you were not expecting.

> A list increasing from 0.1 to 10 in 100 steps of 0.1, run through
> Mod[*,.1] gives 47 wrong answers.

Unexpected, yes. Wrong, no. These would be wrong if you were using exact numbers instead of machine precision numbers.


  • Prev by Date: re:mathematica help
  • Next by Date: Re: Integrate Result depends on symbol used
  • Previous by thread: Re: Mod bug
  • Next by thread: Data Analyst