[Rd] integer

Gabriel Becker gmbecker at ucdavis.edu
Thu Dec 17 16:15:45 CET 2015


Adrian,

Yes, any "whole" number coming out of a computation bitten by floating
point issues, I think.

> x = 1/49*49
> x
[1] 1
> x%%1
[1] 1
> is.wholenumber <-
+     function(x, tol = .Machine$double.eps^0.5)  abs(x - round(x)) < tol
> is.wholenumber(x)
[1] TRUE

Best,
~G

P.S Credit to Hadley Wickham for recently pointing out on twitter that 49
is the first number like this. I would have had to have gone searching for
one otherwise.


On Thu, Dec 17, 2015 at 7:02 AM, Adrian Dușa <dusa.adrian at unibuc.ro> wrote:

> In the help page for ?is.integer, there is this function
>
> is.wholenumber <-
>     function(x, tol = .Machine$double.eps^0.5)  abs(x - round(x)) < tol
>
> A quick question: is there a case where this alternative function will not
> work?
>     function(x) x %% 1 == 0
>
> Best,
> Adrian
>
> --
> Adrian Dusa
> University of Bucharest
> Romanian Social Data Archive
> Soseaua Panduri nr.90
> 050663 Bucharest sector 5
> Romania
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Gabriel Becker, PhD
Associate Scientist (Bioinformatics)
Genentech Research

	[[alternative HTML version deleted]]



More information about the R-devel mailing list