Skip to content

math/big: Float.Text does not correctly handle x format #34343

@larhun

Description

@larhun

What did you do?

see https://play.golang.org/p/IviJWtsbRoW

package main

import (
	"fmt"
	"math/big"
)

func main() {
	var a, _, _ = big.ParseFloat("0x.8p-2147483648", 0, 4, big.ToNearestEven)
	var b, _, _ = big.ParseFloat("0x.8p-2147483647", 0, 4, big.ToNearestEven)

	fmt.Println("a = (x format)", a.Text('x', -1), "(p format)", a.Text('p', -1))
	fmt.Println("b = (x format)", b.Text('x', -1), "(p format)", b.Text('p', -1))
}

What did you expect to see?

a = (x format) 0x1p-2147483649 (p format) 0x.8p-2147483648
b = (x format) 0x1p-2147483648 (p format) 0x.8p-2147483647

What did you see instead?

a = (x format) 0x1p+2147483647 (p format) 0x.8p-2147483648
b = (x format) 0x1p-2147483648 (p format) 0x.8p-2147483647

Please note the wrong +2147483647 exponent for a.Text('x', -1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions