MathGroup Archive 2012

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

Search the Archive

Re: Mod and QuotientRemainder are inconsistent

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124877] Re: Mod and QuotientRemainder are inconsistent
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 10 Feb 2012 05:55:43 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

On 2/9/12 at 5:35 AM, szhorvat at gmail.com (Szabolcs) wrote:

>Mod[12, 0.1] gives 0.1 despite 120*0.1 == 12.  I expect this is
>because 0.1 is not representable in binary.

Yes.

>QuotientRemainder[12, 0.1] gives {120, 0.} however, which is
>inconsistent with the result above.

>Quotient[12,0.1] gives 120 which is also inconsistent with Mod.

>Is this a bug or is it by design?

Neither. It is due to the limitations of using machine precision
arithmetic and your specific hardware.

>It seems it is not safe to assume that

>QuotientRemainder[a,b] == {Quotient[a,b], Mod[a,b]}

>or that

>Quotient[a,b]*b + Mod[a,b] == a

Both relationships will always hold when using exact arithmetic.
But when you are not using exact arithmetic, the relationships
above may not hold.




  • Prev by Date: Re: Mod and QuotientRemainder are inconsistent
  • Next by Date: Re: How to call 'Clear' from within a function?
  • Previous by thread: Re: Mod and QuotientRemainder are inconsistent
  • Next by thread: Looking to "de-simplify"