[Rd] function min does not return correct result if .Machine$integer.max (PR#8732)

ripley at stats.ox.ac.uk ripley at stats.ox.ac.uk
Thu Mar 30 14:55:22 CEST 2006


The code has

     s = INT_MAX;
     for (i = 0; i < n; i++) {
 	if (x[i] != NA_INTEGER) {
 	    if (s > x[i]) {
 		s = x[i];
 		if(!updated) updated = 1;
 	    }
 	}
 	else if (!narm) {
 	    if(!updated) updated = 1;
 	    *value = NA_INTEGER;
 	    return(updated);
 	}
     }
     *value = s;

so it ignores the initial value INT_MAX (updated is not set).  Fairly easy 
to fix ... done for 2.3.0.

There's a parallel problem with -.Machine$integer.max, also fixed.

On Thu, 30 Mar 2006, schlather at hsu-hh.de wrote:

> Full_Name: Martin Schlather
> Version: 2.2.0 and alpha 2.3.0 (06/3/29)
> OS: Linux (x86_64 and Intel)
> Submission from: (NULL) (139.11.183.106)
>
>
>> min(.Machine$integer.max, 10^20)
> [1] 1e+20
>
>> min(as.integer(.Machine$integer.max), 10^20)
> [1] 1e+20
>
>
> but
>> min(.Machine$integer.max + 0, 10^20)
> [1] 2147483647
>
>> min(as.integer(.Machine$integer.max - 1), 10^20)
> [1] 2147483646
>
>> min(as.double(.Machine$integer.max), 10^20)
> [1] 2147483647
>
> Cheers, Martin
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list