From plummerm at iarc.fr  Thu Oct  3 10:15:28 2013
From: plummerm at iarc.fr (Martyn Plummer)
Date: Thu, 3 Oct 2013 08:15:28 +0000
Subject: [Rd] version comparison puzzle
In-Reply-To: <524CE74E.6000208@ufl.edu>
References: <524CE74E.6000208@ufl.edu>
Message-ID: <1380788123.1581.29.camel@braque.iarc.fr>

It's an underflow problem. When comparing versions, "a.b.c" is converted
first to the integer vector c(a,b,c) and then to the double precision
value 

a + b/base + c/base^2

where base is 1 greater than the largest integer component of any of the
versions: i.e 999999912 in this case.  The last term is then smaller
than the machine precision so you can't tell the difference between
1.0.4 and 1.0.5.

Martyn

On Wed, 2013-10-02 at 23:41 -0400, Ben Bolker wrote:
>      Can anyone explain what I'm missing here?
> 
> max(pp1 <- package_version(c("0.99999911.3","1.0.4","1.0.5")))
> ## [1] ?1.0.4?
> 
> max(pp2 <- package_version(c("1.0.3","1.0.4","1.0.5")))
> ## [1] ?1.0.5?
> 
> I've looked at ?package_version , to no avail.
> 
> Since max() goes to .Primitive("max")
> I'm having trouble figuring out where it goes from there:
> I **think** this is related to ?xtfrm , which goes to
> .encode_numeric_version, which is doing something I really
> don't understand (it's in base/R/version.R ...)
> 
> .encode_numeric_version(pp1)
> ## [1] 1 1 1
> ## attr(,"base")
> ## [1] 99999912
> ## attr(,"lens")
> ## [1] 3 3 3
> ## attr(,".classes")
> ## [1] "package_version" "numeric_version"
> 
> .encode_numeric_version(pp2)
> ## [1] 1.083333 1.111111 1.138889
> ## attr(,"base")
> ## [1] 6
> ## attr(,"lens")
> ## [1] 3 3 3
> ## attr(,".classes")
> ## [1] "package_version" "numeric_version"
> 
> sessionInfo()
> R Under development (unstable) (2013-09-09 r63889)
> Platform: i686-pc-linux-gnu (32-bit)
> 
> [snip]
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> loaded via a namespace (and not attached):
> [1] compiler_3.1.0 tools_3.1.0
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] version comparison puzzle
Martyn Plummer