steve said:
On Jan 20, 7:55Â pm, Ben Bacarisse <
[email protected]> wrote:
 In IEEE arithmetic inf times zero is NaN, not 0.
steve <
[email protected]> writes:
Note, there already is a long list of special cases in n1256.pdf.
The ones involving zero:
-- cexp(+-0 + i0) returns 1 + i0.
-- cexp(+inf + i0) returns +inf + i0.
-- cexp(+inf + iy) returns +inf * cis(y) for finite nonzero y.
[Aside: this is not a case involving zero...]
I disgree. The case involves a zero at every y = n * pi / 2 for
integral n.
I don't want to argue about what "involving a zero means". The point is
that the third special case does not tell us what cexp(inf + i0) should
be -- only the previous case does that. The fact that, mathematically,
cexp(x + i*0) = cexp(x + i*2*pi) does mean that C's cexp must treat
these two in the same way. In fact, the rules you quoted show that they
must be treated differently.
[For completeness, G.6.3.1 lists another case involving zero:
-- cexp(-inf + iy) returns +0 * cis(y), for finite y]
cexp(+inf + i0) = exp(+inf) * (cos(0) + i sin(0))
= exp(+inf) * (1 + i 0)
= +inf * (1 + i0)
= +inf + i0 ?
cexp(inf + i0) = inf + i0 because Annex G says so (by the second rule
you quoted). You can't use a derivation to see what you should get. If
this derivation really did apply to that case, the last line above would
read "+inf + iNan".
cexp(+inf + iy) = exp(+inf) * (cos(y) + i sin(y))
= exp(+inf) * (1 + i 0) for y = n * pi
I think it's exp(+inf) * (-1^n + i0) but I don't think that alters your
point.
= +inf * (1 + i0)
= +inf + i0 ?
That last line should be
-1^n * inf + i*Nan
which is what the third rule mandates when y is not zero. The
derivation helps to explain the rule.
However, as Ian has pointed out, since pi can't be represented what
should be i0 will really be a small non-zero imaginary part. The result
is therefore likely to be
-1^n * inf + i*inf
with an arbitrary sign for the imaginary part. (In fact, I think you
can predict the sign of the imaginary infinity if you know which side of
pi your approximation uses.)
I have a newer draft of IEEE 754 on some computer. But
given the above quotes, a result of inf + i NAN seems
correct to the y = n * pi case.
Except that y is never = n * pi so sin(y) is unlikely to be zero. I
don't think there is anything stopping an implementation returning zero
for sin(y) when y is very close to n * pi, but I don't think it's
required and it seems unlikely in practise.
In this case, glibc's return of "-inf inf" for cexp(inf + i*pi) looks
correct (for a close approximation to pi).
It still looks as if the C standard does not say what the answer should
be, though "inf 0" and "inf Nan" seem to be more helpful than "inf inf"
which is what my gcc + glibc gives me.
Can't help with gcc+glibc. Now, if you use FreeBSD, I may
be of help eventually (depends on whether my cexp[fl] make
it into libm).
What result have you decided on for cexp(1000 + i0)?
<snip>