Issue 23563 in dart: double.operator-() is unstable

7 views
Skip to first unread message

da...@googlecode.com

unread,
Jun 1, 2015, 9:20:13 AM6/1/15
to bu...@dartlang.org
Status: Triaged
Owner: ----
Labels: Type-Defect Priority-Unassigned Area-VM

New issue 23563 by ajoh...@google.com: double.operator-() is unstable
https://code.google.com/p/dart/issues/detail?id=23563

The following:

print(identical(double.NAN, -double.NAN));

will print true at first, but false when optimized.

Note that the initial behavior is unexpected, as the compare is bitwise but
the sign-bit is not changed.


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

da...@googlecode.com

unread,
Jun 1, 2015, 2:45:48 PM6/1/15
to bu...@dartlang.org
Updates:
Status: Accepted
Owner: srd...@google.com

Comment #1 on issue 23563 by srd...@google.com: double.operator-() is
unstable
https://code.google.com/p/dart/issues/detail?id=23563

(No comment was entered for this change.)

da...@googlecode.com

unread,
Jun 1, 2015, 4:07:09 PM6/1/15
to bu...@dartlang.org
Updates:
Cc: gbr...@google.com ko...@google.com

Comment #2 on issue 23563 by srd...@google.com: double.operator-() is
unstable
https://code.google.com/p/dart/issues/detail?id=23563

It seems to me that similarly to 0.0, unary minus must treat NaN-s
specially so that double.Nan & -double.NaN are not identical

da...@googlecode.com

unread,
Jun 1, 2015, 4:16:30 PM6/1/15
to bu...@dartlang.org

Comment #3 on issue 23563 by ko...@google.com: double.operator-() is unstable
https://code.google.com/p/dart/issues/detail?id=23563

Quotes directly from the IEEE 754-1985 standard
http://homepages.math.uic.edu/~jan/mcs471/Lec3/ieee754.pdf
(which is the only official full text version I have found so far):

"Every operation involving one or two input NaNs, none of them signaling,
shall signal no exception but, if a floating-point result is to be
delivered,
shall deliver as its result a quiet NaN, which should be one of the input
NaNs."

This seems to require -x to "one of the input NaNs", and thus, it must be
exactly x.

Furthermore, it states: "This standard does not interpret the sign of an
NaN"

da...@googlecode.com

unread,
Jun 1, 2015, 4:37:55 PM6/1/15
to bu...@dartlang.org
Updates:
Cc: floi...@google.com

Comment #4 on issue 23563 by ajoh...@google.com: double.operator-() is
unstable
https://code.google.com/p/dart/issues/detail?id=23563

+floitsch

I'm not sure how to interpret it, but it says 'should', not 'must'. Also,
the spec does not contain information about negate, only add, minus, mul,
div and mod.

da...@googlecode.com

unread,
Jun 1, 2015, 4:44:37 PM6/1/15
to bu...@dartlang.org

Comment #5 on issue 23563 by ko...@google.com: double.operator-() is unstable
https://code.google.com/p/dart/issues/detail?id=23563

Scratch all that, there's a newer version of the standard, which goes into
more detail.

http://754r.ucbtest.org/drafts/archive/2006-10-04.pdf

"
7.5.1 Sign operations
7.5.1.0
Implementations shall provide the following homogeneous quiet-computational
sign operations for all
supported non-storage floating-point formats. They might propagate
non-canonical encodings. They are
performed as if on strings of bits, treating floating-point numbers and
NaNs alike, and hence signal no
exception.
...
negate(x) copies a floating-point operand x to a destination in the same
format, reversing the sign.
0–x is not the same as –x or negate(x).
"

Note that very last comment... so I'm still not sure what is
mandated/allowed for "-x" when x is a quiet NaN.

da...@googlecode.com

unread,
Jun 1, 2015, 4:47:48 PM6/1/15
to bu...@dartlang.org

Comment #6 on issue 23563 by ajoh...@google.com: double.operator-() is
unstable
https://code.google.com/p/dart/issues/detail?id=23563

So basically copy and swap the sign bit. To me that sounds like optimized
version is correct so that returning a NaN with the sign-bit reversed is
the right solution.

da...@googlecode.com

unread,
Jun 1, 2015, 4:51:02 PM6/1/15
to bu...@dartlang.org

Comment #7 on issue 23563 by srd...@google.com: double.operator-() is
unstable
https://code.google.com/p/dart/issues/detail?id=23563

The agreement is that identical(double.NaN, -double.NaN) should always
return false.

da...@googlecode.com

unread,
Jun 2, 2015, 4:11:13 PM6/2/15
to bu...@dartlang.org

Comment #8 on issue 23563 by srd...@google.com: double.operator-() is
unstable
https://code.google.com/p/dart/issues/detail?id=23563

There is a problem of implementing unary- for NaNs. double.isNegative
always returns false for any nan, i.e., it is not possible to implement
unary- in a similar way as for 0.0.

I am puzzled why double.isNegative does not work same as C-s 'signbit'. Any
insight?
Reply all
Reply to author
Forward
0 new messages