Re: Problem using Quotient and Mod functions with rational parameters
- To: mathgroup at smc.vnet.net
- Subject: [mg41880] Re: Problem using Quotient and Mod functions with rational parameters
- From: bobhanlon at aol.com (Bob Hanlon)
- Date: Sun, 8 Jun 2003 06:45:44 -0400 (EDT)
- References: <bbrpdr$j72$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
You referred to rational parameters but are using inexact numbers. Even though Equal shows 0.29==29/100 True The machine representation is less 0.29<29/100 True Similarly, {0.29/0.01 == 29, 0.29/0.01 < 29} {True, True} If you want exact results you must use exact numbers {Quotient[29/100,1/100], Quotient[Rationalize[0.29], Rationalize[0.01]], Mod[29/100,1/100], Mod[Rationalize[0.29],Rationalize[0.01]]} {29, 29, 0, 0} Bob Hanlon In article <bbrpdr$j72$1 at smc.vnet.net>, eduault <eduault at yahoo.com> wrote: << Subject: Problem using Quotient and Mod functions with rational parameters From: eduault <eduault at yahoo.com> To: mathgroup at smc.vnet.net Date: Sat, 7 Jun 2003 04:24:27 +0000 (UTC) As a Mathematica user, I was recently surprised by the result returned by the Quotient and Mod functions, called with some rational parameters. I was expecting that Quotient[m*n, n], with m positive integer and a positive would return m. This is nearly almost the case, for example: Quotient[0.12, 0.01] returns 12 Quotient[0.13, 0.01] returns 13 Quotient[0.14, 0.01] returns 14 However, for some parameters, this is not the case: Quotient[0.29, 0.01] returns 28 Quotient[0.57, 0.01] returns 56 Quotient[0.58, 0.01] returns 57 Quotient[0.59, 0.01] returns 58 Does someone explain those results, which I observed using Mathematica versions 4.0.1.0 and 4.0.2.0, and two different machines (PCs with Windows NT and Windows 98) ?? --------------------------------------------------------------------- Note: The same behavior occurs with the Mod function. This relation between Quotient and Mod is normal, because of the relation found in the documentation, saying that "Mod[m, n] is equivalent to m - n Quotient[m, n]". But this leads to some surprising results: Mod[m*n, n] should return 0, as in most cases: (I agree with this result) Mod[0.12, 0.01] returns 0 Mod[0.13, 0.01] returns 0 Mod[0.14, 0.01] returns 0 but we also have, for rare parameters: Mod[0.29, 0.01] returns 0.01 Mod[0.57, 0.01] returns 0.01 Mod[0.58, 0.01] returns 0.01 Mod[0.59, 0.01] returns 0.01 >><BR><BR>