Re: bug in remainder ?
- Posted by Everett Williams <rett at GVTC.COM> Feb 03, 2000
- 415 views
On Thu, 3 Feb 2000 16:19:45 -0500, Brian Broker <bkb at CNW.COM> wrote: >On Thu, 3 Feb 2000 16:09:48 -0500, Brian Broker <bkb at CNW.COM> wrote: > >>On Thu, 3 Feb 2000 20:21:04 +0000, Daniel Johnson wrote: >> >>>? remainder(1,.1) >>>.1 >>>? remainder(1,.01) >>>.01 >>>? remainder(10,1) >>>1 >> >>I get: >>0.1 >>0.01 >>0 > >Hmmm... now that I think about it, shouldn't they all be zero? What am I >missing here? > >? remainder( 3.5, 1.7 ) >for example, correctly outputs 0.1 > >-- Brian Here's the definition from the manual Syntax: x3 = remainder(x1, x2) Description: Compute the remainder after dividing x1 by x2. The result will have the same sign as x1, and the magnitude of the result will be less than the magnitude of x2. Comments: The arguments to this function may be atoms or sequences. The rules for operations on sequences apply. By this, any even multiple should provide an answer of zero, but if an enterprising interpreter were to convert .01 or any other decimal value less than 0 to a float before doing the the division, the answer would always come out slightly different than one would expect because of rounding errors. To get an accurate value, one must move the decimal on both the divisor and the dividend so that both are whole numbers and then scale the remainder. ? remainder(10,1)/10 0 ? remainder(100,1)/100 0 ? remainder(10,1) 0 Everett L.(Rett) Williams rett at gvtc.com