Displaying 1 result from an estimated 1 matches for "decbase".
Did you mean:
declbase
2004 Feb 06
1
0.1 + 0.2 != 0.3 revisited
Prompted by Peter Dalgard's recent elegant "intbin" function,
I have been playing with the extension to converting reals to binary
representation. The decimal part can be done like this:
decbase <- function(x, n=52, base=2) {
if(n) {
x <- x*base
paste(trunc(x), decbase(x%%1, n-1, base), sep="")
}
}
n=52 default because that's the number of bits in the significand of
a 64-bit float.
Now, `decbase(0.1)` is a bit curious in that the 0.1 is going to be
convert...