To: J3 J3/18-160
From: Anton Shterenlikht
Subject: Allowing real and imaginary zero arguments to LOG(X)
Date: 2018-May-25
References: N2146, ISO/IEC 9899:2011 (Programming languages - C)
Introduction:
~~~~~~~~~~~~~
The LOG intrinsic will be marginally more useful
if real and complex zero arguments were allowed.
In N2146 ATAN can take inputs
(+0,+1), (-0,+1), (-0,-1) and (+0,-1),
and produce results with arbitrary finite
real part and infinite imaginary part with the correct sign.
By analogy LOG(+-0, +-0) should be allowed,
with the resulting value of negative infinity
real part and arbitrary finite imaginary part
with the correct sign.
The exact value of the imaginary part is immaterial,
provided it is finite and normal.
For consistency with C11 (see below) the
following result values are proposed:
LOG(-0,+0) = (-inf, {pi} )
LOG(+0,+0) = (-inf, +0 )
LOG(-0,-0) = (-inf, -{pi} )
LOG(+0,-0) = (-inf, -0 )
LOG(+-0) should also be allowed, with the resulting value
of negative infinity.
This change will make the identity:
Z**A = EXP( A * LOG(Z) )
valid for all values of z, including zero,
so that arguments Z=+-0 or Z=(+-0,+-0) will require no
special code.
Logarithm in C11
~~~~~~~~~~~~~~~~
It is instructive to note that C11 (since C99) does allow
real and complex zero arguments for logarithms:
From ISO/IEC 9899:2011 (Programming languages - C),
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf:
*quote*
F.10.3.7 The log functions
log(+-0) returns -inf and raises the "divide-by-zero"
floating point exception.
*end quote*
*quote*
G.6.3.2 The clog functions
clog(-0+i0) returns -inf + i{pi} and raises the "divide-by-zero"
floating point exception.
clog(+0+i0) returns -inf + i0 and raises the "divide-by-zero"
floating point exception.
*end quote*
It seems C11 does not explicitly define the two
remaining cases: clog(-0,-i0) and clog(+0,-i0).
Perhaps they thought it obvious.
The return values for these two arguments,
suggested above, seem reasonable.
Edits to N2146
~~~~~~~~~~~~~~
In 16.9.118 LOG (X), para 3 Argument, delete:
"If X is real, its value shall be greater than zero.
If X is complex, its value shall not be zero.",
so the whole of para 3 reads:
"Argument. X shall be of type real or complex."
The following edit, specifying the result values
for real and complex zero arguments, is optional.
If we want to put this in, then we ought to add
similar text to ATAN(X).
In para 5, Result Value, add:
"If X is real and zero, the result is minus infinity.
If X is complex and both the real and the imaginary
parts are zero, the result values are as follows:
LOG(-0,+0) = (-inf, {pi} ), LOG(+0,+0) = (-inf, +0 ),
LOG(-0,-0) = (-inf, -{pi} ), LOG(+0,-0) = (-inf, -0 )."