]> Cypherpunks repositories - gostls13.git/commit
math/big: round x + (-x) to -0 for mode ToNegativeInf
authorBrian Kessler <brian.m.kessler@gmail.com>
Fri, 8 Jun 2018 17:48:18 +0000 (11:48 -0600)
committerRobert Griesemer <gri@golang.org>
Thu, 14 Jun 2018 21:07:01 +0000 (21:07 +0000)
commitd31cad7ca52580cfc7048766599e6cddeab3c61c
treece95e9b32e84f39e149f19946e9c58730baddd3d
parentc359d759a77fcec1457f3eb5c5d04fb74f47dad4
math/big: round x + (-x) to -0 for mode ToNegativeInf

Handling of sign bit as defined by IEEE 754-2008, section 6.3:

When the sum of two operands with opposite signs (or the difference of
two operands with like signs) is exactly zero, the sign of that sum (or
difference) shall be +0 in all rounding-direction attributes except
roundTowardNegative; under that attribute, the sign of an exact zero
sum (or difference) shall be −0. However, x+x = x−(−x) retains the same
sign as x even when x is zero.

This change handles the special case of Add/Sub resulting in exactly zero
when the rounding mode is ToNegativeInf setting the sign bit accordingly.

Fixes #25798

Change-Id: I4d0715fa3c3e4a3d8a4d7861dc1d6423c8b1c68c
Reviewed-on: https://go-review.googlesource.com/117495
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/math/big/float.go
src/math/big/float_test.go