From Ted.Harding at nessie.mcc.ac.uk  Wed Jun  1 11:50:14 2005
From: Ted.Harding at nessie.mcc.ac.uk ( (Ted Harding))
Date: Wed Jun  1 12:01:05 2005
Subject: [Rd] 1/tan(-0) != 1/tan(0)
In-Reply-To: <17053.28658.832404.930124@stat.math.ethz.ch>
Message-ID: <XFMail.050601105014.Ted.Harding@nessie.mcc.ac.uk>

On 01-Jun-05 Martin Maechler wrote:
> Testing the code that Morten Welinder suggested for improving
> extreme tail behavior of  qcauchy(),
> I found what you can read in the subject.
> namely that the tan() + floating-point implementation on all
> four different versions of Redhat linux, I have access to on
> i686 and amd64 architectures,
> 
>     > 1/tan(c(-0,0))
> gives
>     -Inf  Inf
> 
> and of course, that can well be considered a feature, since
> after all, the tan() function does jump from -Inf to +Inf at 0. 
> I was still surprised that this even happens on the R level,
> and I wonder if this distinction of "-0" and "0" shouldn't be
> mentioned in some place(s) of the R documentation.

Indeed I would myself consider this a very useful feature!

However, a query: Clearly from the above (ahich I can reproduce
too), tan() can distinguish between -0 and +0, and return
different results (otherwise 1/tan() would not return different
results).

But how can the user tell the difference between +0 amnd -0?
I've tried the following:

  > sign(c(-0,0))
  [1] 0 0
  > sign(tan(c(-0,0)))
  [1] 0 0
  > sign(1/tan(c(-0,0)))
  [1] -1  1

so sign() is not going to tell us. Is there a function which can?

Short of wrting one's own:

  sign0 <-
    function(x){
      if(abs(x)>0) stop("For this test x must be +0 or -0")
      return(sign(1/tan(x)))
    }

;)

Best wishes,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding@nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 01-Jun-05                                       Time: 10:50:06
------------------------------ XFMail ------------------------------


[Rd] 1/tan(-0) != 1/tan(0)
 (Ted Harding