From gmbecker at ucdavis.edu  Thu Dec 17 16:15:45 2015
From: gmbecker at ucdavis.edu (Gabriel Becker)
Date: Thu, 17 Dec 2015 07:15:45 -0800
Subject: [Rd] integer
In-Reply-To: <CAJ=0CtDxVZzpNbE2ZvBK3Ki2TCuO929Hi_MvLwRH2aOGU7OxTQ@mail.gmail.com>
References: <CAJ=0CtDxVZzpNbE2ZvBK3Ki2TCuO929Hi_MvLwRH2aOGU7OxTQ@mail.gmail.com>
Message-ID: <CADwqtCNpTc5WWNjq04y2kb8S3vijS+uVrw5R8yfOMXkckyJnsQ@mail.gmail.com>

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]]



[Rd] integer
Gabriel Becker