From ggrothendieck at gmail.com  Wed Jun  1 19:31:59 2005
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Wed Jun  1 19:32:07 2005
Subject: [Rd] 1/tan(-0) != 1/tan(0)
In-Reply-To: <5F845940-4389-4E68-8EE9-0F45094A8E11@r-project.org>
References: <XFMail.050601105014.Ted.Harding@nessie.mcc.ac.uk>
	<5F845940-4389-4E68-8EE9-0F45094A8E11@r-project.org>
Message-ID: <971536df0506011031fad5d21@mail.gmail.com>

On 6/1/05, Simon Urbanek <simon.urbanek@r-project.org> wrote:
> On Jun 1, 2005, at 5:50 AM, (Ted Harding) wrote:
> 
> > 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?
> 
> That's indeed a good question - by definition (-0)==(+0) is true,
> -0<0 is false and signum of both -0 and 0 is 0.
> 
> I don't see an obvious way of distinguishing them at R level. Besides
> computational ways (like the 1/tan trick) the only (very ugly) way
> coming to my mind is something like:
> a==0 && substr(sprintf("%f",a),1,1)=="-"
> Note that print doesn't display the sign, only printf does.

On my XP machine running R 2.1.0 patched 2005-05-14

> sprintf("%f",-0)
[1] "0.000000"

does not print the sign.

however, the tan trick can be done without tan using just division:

R> sign0 <- function(x) if (x != 0) stop("x not zero") else sign(1/x)
R> sign0(0)
[1] 1
R> sign0(-0)
[1] -1


[Rd] 1/tan(-0) != 1/tan(0)
Gabor Grothendieck