in reply to Re^3: Negative zero from a multiplication by a zero?
in thread Negative zero from a multiplication by a zero?

If you were desperate, you could compile a perl with PERL_PRESERVE_IVUV turned off.

Hey ... that works!! (No, I'm not desperate - just anal :-)

Any arithmetic operation on IV's now seems to turn them into NV's so (-2 * 0) reports -0 even though the original operands are IV's.
(2 * -0) reports 0, but that's to be expected given the underlying events.
(2 * -0.0) does report -0, again as expected.

One thing I did find while building this perl was that 'dmake test' reported 2 failures in the Devel::Peek tests - all other tests passed. I suspect those 2 Devel::Peek tests might be overlooking the possibility of NO_PERL_PRESERVE_IVUV being defined. I'll check that out properly later today, and submit a bug report.

Cheers,
Rob

Replies are listed 'Best First'.
Re^5: Negative zero from a multiplication by a zero? (negative)
by tye (Sage) on Jun 13, 2009 at 04:47 UTC

    Somebody should just fix the bad floating point implementation / standard. Having -1.2 * 0 be -0 rather seriously misses the point of "negative zero" and brings it into play in places where it has no business and is just a royal pain with no benefit.

    If you want to detect the sign of your underflow, you should bother to check before multiplying by a negative value or you should get a floating point implementation that distinguishes "zero" from "positive zero" (but most floating point implementations don't do that because "negative zero" was partly motivated by having a spare bit handy and there isn't as handy of a bit to make "positive zero" out of).

    Surely we need "negative NaN" as much as "negative zero". We must distinguish +Inf * 0 from +Inf * -0, surely. At least, it makes just as much sense as having "negative zero" for one underflow case (but not having a special value for "positive underflow", much less another for "underflow of indeterminate sign").

    - tye        

      Surely we need "negative NaN" as much as "negative zero".

      Sssshhh ... you'll give 'em ideas.
      The standard that I find really absurd is NaN ** 0 being defined as 1. The logic seems to be that since *all* numbers raised to the power 0 are 1, then NaN ** 0 should also be 1. (Those who create these standards are apparently unaware of the fact that a NaN is not a number.)

      Cheers,
      Rob