Reduction operations in P1788/D9.5
P1788
On 10 Jan 2015, at 18:13, Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> On 2015-01-10 15:13:09 +0200, Hossam A. H. Fahmy wrote:
>> sumAbs(2, 3, +\infty, NaN)=+\infty
>> while
>> sum(2, 3, +\infty, NaN)=NaN.
>> Is this desired?
>
> Yes: if you replace NaN by any number x (finite or infinite),
> sumAbs(2, 3, +\infty, x) will give +\infty. This is not true
> for sum as +\infty + -\infty is an indeterminate form.
>
>> The opposite order: "if a NaN is encountered, NaN shall be returned.
>> Otherwise, if an infinity is encountered, $+\infty$ shall be returned."
>> gives precedence to NaN. Which order is needed in P1788 applications?
>>
>> For those in the group who were also part of 754-2008: Was this change
>> of order intentional in 754-2008 or an oversight? (I personally do not
>> remember!)
>
> This is consistent with the choice where NaN is regarded as
> any number, not an error, like in hypot.
Those who took part in producing IEEE Std 754-2008 (754 for short) may shoot this down, but here is a suggestion.
754 is fairly clear on what NaN *does* -- the Level 2. (Actually it's vague on the Level 2 of NaN payloads.) It is vague on what NaN *is* -- the Level 1. Of several views of NaN at Level 1, two are
A. NaN is the result of a previous error.
B. NaN stands for an unknown number, finite or infinite.
I think Hossam is taking view A, while the 754definition of reduction operations is based on view B. (One must also consider, as Siegfried Rump has often pointed out, that Inf also has two meanings: genuine infinity, and a number whose FP approximation became too large to represent as finite.)
However 754 does distinguish sNaN from qNaN. My suggestion is that 1788 might use these for views A and B. This can be done by a sentence in 12.12.12 such as
In this standard, in any IEEE 754 format, a signaling NaN is regarded
as the result of a previous error, while a quiet NaN stands for an
unknown number, finite or infinite.
A similar entry might be put in the Definitions.
(BTW: Jonathan Goldberg explained to me the difference between "IEEE 754", "IEEE Std 754" and "IEEE Std 754-2008", and I think I have it right, above.)
The precedence rule for sumAbs, implied by this Level 1 meaning, would then be
If an sNaN is encountered, sNaN shall be returned. Otherwise, if
an Infinity is encountered, +oo shall be returned. Otherwise, if
a qNaN is encountered, qNaN shall be returned.
I guess this affects dot and sum also, and maybe the "All other behavior" on p63 line 27.
Michel, and others expert in low-level aspects, can say if this fits well with the 754-defined behaviour of sNaN and qNaN, and if it can implemented efficiently enough that the extra clarity outweighs the cost.
John Pryce