Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/big: round x + (-x) to -0 for mode ToNegativeInf #25798

Closed
bmkessler opened this issue Jun 8, 2018 · 1 comment
Closed

math/big: round x + (-x) to -0 for mode ToNegativeInf #25798

bmkessler opened this issue Jun 8, 2018 · 1 comment
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bmkessler
Copy link
Contributor

The source of float.go contains the following comment about handling the sign bit for Add/Sub

// Handling of sign bit as defined by IEEE 754-2008, section 6.3:
//
// When neither the inputs nor result are NaN, the sign of a product or
// quotient is the exclusive OR of the operands’ signs; the sign of a sum,
// or of a difference x−y regarded as a sum x+(−y), differs from at most
// one of the addends’ signs; and the sign of the result of conversions,
// the quantize operation, the roundToIntegral operations, and the
// roundToIntegralExact (see 5.3.1) is the sign of the first or only operand.
// These rules shall apply even when operands or results are zero or infinite.
//
// 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.
//
// See also: https://play.golang.org/p/RtH3UCt5IH

And the documentation for func (z *Float) Add(x, y *Float) *Float notes that rounding mode ToNegativeInf does not correctly follow this spec.

// BUG(gri) When rounding ToNegativeInf, the sign of Float values rounded to 0 is incorrect.

@griesemer

@gopherbot
Copy link

Change https://golang.org/cl/117495 mentions this issue: math/big: round x + (-x) to -0 for mode ToNegativeInf

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 8, 2018
@bcmills bcmills added this to the Go1.11 milestone Jun 8, 2018
@golang golang locked and limited conversation to collaborators Jun 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants