Re: [Rd] Different results for tan(pi/2) and tanpi(1/2)

2016-09-09 Thread William Dunlap via R-devel
Other examples of functions like this are log1p(x), which is log(1+x) accurate for small x, and expm1(x), which is exp(x)-1 accurate for small x. E.g., > log1p( 1e-20 ) [1] 1e-20 > log( 1 + 1e-20 ) [1] 0 log itself cannot be accurate here because the problem is that 1 == 1 + 1e-20 in

Re: [Rd] Different results for tan(pi/2) and tanpi(1/2)

2016-09-09 Thread Greg Snow
If pi were stored and computed to infinite precision then yes we would expect tan(pi/2) to be NaN, but computers in general and R specifically don't store to infinite precision (some packages allow arbitrary (but still finite) precision) and irrational numbers cannot be stored exactly. So you

Re: [Rd] Different results for tan(pi/2) and tanpi(1/2)

2016-09-09 Thread William Dunlap via R-devel
tanpi(x) should be more accurate than tan(pi*x), especially near multiples of pi/2. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Sep 9, 2016 at 11:55 AM, Hans W Borchers wrote: > The same argument would hold for tan(pi/2). > I don't say the result 'NaN' is wrong,

Re: [Rd] Different results for tan(pi/2) and tanpi(1/2)

2016-09-09 Thread Hans W Borchers
The same argument would hold for tan(pi/2). I don't say the result 'NaN' is wrong, but I thought, tan(pi*x) and tanpi(x) should give the same result. Hans Werner On Fri, Sep 9, 2016 at 8:44 PM, William Dunlap wrote: > It should be the case that tan(pi*x) != tanpi(x) in many

Re: [Rd] Different results for tan(pi/2) and tanpi(1/2)

2016-09-09 Thread William Dunlap via R-devel
It should be the case that tan(pi*x) != tanpi(x) in many cases - that is why it was added. The limits from below and below of the real function tan(pi*x) as x approaches 1/2 are different, +Inf and -Inf, so the limit is not well defined. Hence the computer function tanpi(1/2) ought to return

Re: [Rd] Different results for tan(pi/2) and tanpi(1/2)

2016-09-09 Thread John McKown
On Fri, Sep 9, 2016 at 12:24 PM, Hans W Borchers wrote: > As the subject line says, we get different results for tan(pi/2) and > tanpi(1/2), though this should not be the case: > > > tan(pi/2) > [1] 1.633124e+16 > > > tanpi(1/2) > [1] NaN > Warning