Skip to content

math/big: Float.Float32() does not correctly handle denormals that are rounded up to a power of 2 #14553

@tarm

Description

@tarm

Context for this issue is https://groups.google.com/forum/#!topic/golang-dev/8xrGLS6mzzE

It appears to be a bug in the rounding of big.Float.Float32() and
Float64(), which the compiler uses to convert constants to float32 and
float64.

Specifically the bug happens when 1) the float32/64 constant is a
tiny, denormal value, 2) the arbitrary precision value would have to
round up to a bit representation with more precision. So for example
0x7.9p-149 should round up to 0x8.0p-149 when converted to a float32,
but the existing code actually gets stuck at 3 bits of precision while
still overflowing the mantissa so 0x4.0p-149 is actually what gets
assigned (which is worse than rounding down to 0x7.0p-149).

Here is a playground link that shows the problem:
http://play.golang.org/p/_aMEvOuOAs

To be fair, several places in the git commit history and in the
comments discuss how math.Float does not completely handle denormal
values. On the other hand, it seems like the compiler should be able
to parse and assign them properly.

go v1.6, linux, x64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions