>Is this a consequence of machine error or something else?
>Could this be overcome? (It works correctly when integers are used in
>the sequences as well as in many other circumstances)
The usual solution for testing a==b with floating-point round-off error is
abs(a-b) X1=seq(0,1,len=11)
> X2=seq(
...and so say google [http://www.google.com/search?q=1%250.1]:
"1 modulo 0.1 = 0.1",
so end of discussion ;)
In bit of a food coma now, but the following is interesting:
r = a %% b
<=>
r = (b*a/b) %% (b*b/b)
<=>
r = b*((a/b) %% 1)
> modulo <- function(a, b) { b * ((a/b) %% 1) }
On 4/19/2007 4:29 PM, Bernhard Klingenberg wrote:
> Thank you! Is floating point arithmetic also the reason why
>
> 1 %% 0.1
>
> gives the "surprising" answer 0.1 (because 0.1 cannot be written as a
> fraction with denominator a power of 2, e.g. 1%%0.5 correctly gives 0).
>
> This seems to go
Bernhard Klingenberg wrote:
>
> Thank you! Is floating point arithmetic also the reason why
>
> 1 %% 0.1
>
> gives the "surprising" answer 0.1
>
Floating point arithmetic is one of the most Evil things
computer science imposed against the mathematicians; any
reasonable person, back when comput
Thank you! Is floating point arithmetic also the reason why
1 %% 0.1
gives the "surprising" answer 0.1 (because 0.1 cannot be written as a
fraction with denominator a power of 2, e.g. 1%%0.5 correctly gives 0).
This seems to go a bit against the statement in the help for '%%', which
states "F
On 4/18/07, Bernhard Klingenberg <[EMAIL PROTECTED]> wrote:
> Consider the code:
>
> x <- seq(0,1,0.2)
> y <- seq(0,1,0.01)
> cbind(match(y,x),y)
>
> which, surprisingly, doesn't show a match at 0.6! (It gives correct
> matches at 0, 0.2, 0.4, 0.8 and 1, though)
>
> In addition,
>
> x[4]==y[61]
>
>
Consider the code:
x <- seq(0,1,0.2)
y <- seq(0,1,0.01)
cbind(match(y,x),y)
which, surprisingly, doesn't show a match at 0.6! (It gives correct
matches at 0, 0.2, 0.4, 0.8 and 1, though)
In addition,
x[4]==y[61]
yields FALSE. (but x[5]==y[81], the one for 0.8, yields TRUE)
Is this a consequ