
On Mon, Oct 15, 2001 at 03:52:06PM +0200, Kent Karlsson wrote:
Simon Peyton-Jones:
Russell O'Connor suggests: | but sinh and cosh can easily be defined in terms of exp | sinh x = (exp(x) - exp(-x))/2 | cosh x = (exp(x) + exp(-x))/2 ... This looks pretty reasonable to me. We should have default methods for anything we can. Mathematically, yes. Numerically, no. Even if 'exp' is implemented with high accuracy, the suggested defaults may return a very inaccurate (in ulps) result. Take sinh near zero. sinh(x) with x very close to 0 should return x. With the above 'default' sinh(x) will return exactly 0 for a relatively wide interval around 0, which is the wrong result except for 0 itself.
Hmm, on these grounds the current default definition for tanh x is even worse behaved: tanh x = sinh x / cosh x For moderately large floating point x, this will overflow. Frankly, I don't think the whole discussion matters very much; nobody who cares will use the default definitions. But remember to think about branch cuts. And why not go further? cos x = (exp (i*x) + exp (-i*x))/2 where i = sqrt (-1) etc.
In general, this is why LIA-2 (Language Independent Arithmetic, part 2, "Elementary numerical functions", ISO/IEC 10967-2:2001) rarely attempts to define one numerical operation in terms of other numerical operations. That is done only when the relationship is exact (even if the operations themselves are inexact). That is not the case for the abovementioned operations. But it is the case for the relationship between the complex sin operation and the complex sinh operation, for instance. (Complex will be covered by LIA-3.)
This sounds like a very interesting standard. I am constantly annoyed by ISO's attempts to hide their standards; one might wonder what the purpose is of having unavailable "standards". Is the content available somewhere? Best, Dylan Thurston