diff --git a/src/math/all_test.go b/src/math/all_test.go index a145c5e60b..1ac8ce886c 100644 --- a/src/math/all_test.go +++ b/src/math/all_test.go @@ -1967,6 +1967,8 @@ var vfldexpBC = []fi{ {-1, -1075}, {1, 1024}, {-1, 1024}, + {1.0000000000000002, -1075}, + {1, -1075}, } var ldexpBC = []float64{ SmallestNonzeroFloat64, @@ -1977,6 +1979,8 @@ var ldexpBC = []float64{ Copysign(0, -1), Inf(1), Inf(-1), + SmallestNonzeroFloat64, + 0, } var logbBC = []float64{ diff --git a/src/math/ldexp.go b/src/math/ldexp.go index b5d2a5e7e8..aa50a49ade 100644 --- a/src/math/ldexp.go +++ b/src/math/ldexp.go @@ -25,7 +25,7 @@ func ldexp(frac float64, exp int) float64 { exp += e x := Float64bits(frac) exp += int(x>>shift)&mask - bias - if exp < -1074 { + if exp < -1075 { return Copysign(0, frac) // underflow } if exp > 1023 { // overflow @@ -36,8 +36,8 @@ func ldexp(frac float64, exp int) float64 { } var m float64 = 1 if exp < -1022 { // denormal - exp += 52 - m = 1.0 / (1 << 52) // 2**-52 + exp += 53 + m = 1.0 / (1 << 53) // 2**-53 } x &^= mask << shift x |= uint64(exp+bias) << shift