To answer part 1) of your question, see point 7.31 in the R FAQ
(http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-
numbers-are-equal_003f).

> 0.3 - 3*0.1
[1] -5.551115e-17

It always amazes me in how many different guises the problem of floating
point representation crops up.

HTH
 

>-----Original Message-----
>From: [EMAIL PROTECTED] 
>[mailto:[EMAIL PROTECTED] On Behalf Of 
>Jonathan Williams
>Sent: 22 November 2006 12:15 PM
>To: Ethz. Ch
>Subject: [R] odd behaviour of %%?
>
>Dear R Helpers,
>
>I am trying to extract the modulus from divisions by a 
>sequence of fractions.
>I noticed that %% seems to behave inconsistently (to my untutored eye),
>thus:
>
>> 0.1%%0.1
>[1] 0
>> 0.2%%0.1
>[1] 0
>> 0.3%%0.1
>[1] 0.1
>> 0.4%%0.1
>[1] 0
>> 0.5%%0.1
>[1] 0.1
>> 0.6%%0.1
>[1] 0.1
>> 0.7%%0.1
>[1] 0.1
>> 0.8%%0.1
>[1] 0
>> 0.9%%0.1
>
>The modulus for 0.1, 0.2, 0.4 and 0.8 is zero, as I'd expect. 
>But, the modulus for 0.3, 0.6, 0.7 and 0.9 is 0.1 - which I 
>did not expect. I can see no obvious rule that predicts 
>whether x%%0.1 will give an answer of 0 or 0.1.  I could find 
>no explanation of the way that %% works in the R manuals. So, I have 3
>questions:-
>
>1) Why is the modulus of 0.3%%0.1 (and 0.5%%0.1 and 
>0.6%%0.1...) not zero?
>2) Are there any algorithms in R that use the %% operator with 
>fractional divisors in this way, and do they know about its 
>apparently inconsistent behaviour?
>3) If %% is not intended for use with fractional divisors, 
>then would it be a good idea to trap attempts to use them?
>
>Thanks, in advance, for your help
>
>Jonathan Williams
>
>______________________________________________
>R-help@stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide 
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
>

********************
Nedbank Limited Reg No 1951/000009/06. The following link displays the names of 
the Nedbank Board of Directors and Company Secretary. [ 
http://www.nedbank.co.za/terms/DirectorsNedbank.htm ]
This email is confidential and is intended for the addressee only. The 
following link will take you to Nedbank's legal notice. [ 
http://www.nedbank.co.za/terms/EmailDisclaimer.htm ]
********************

        [[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to