Re: [Rd] 1/tan(-0) != 1/tan(0)

From: Simon Urbanek <simon.urbanek_at_r-project.org>
Date: Wed 01 Jun 2005 - 17:01:55 GMT

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.

At C level it's better - you can use the signbit() function/macro there. Any other ideas?

Cheers,
Simon



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Jun 02 03:07:35 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:06 GMT