]> Cypherpunks repositories - gostls13.git/commit
math/rand: Float32/64 must only return values in [0,1)
authorJeff R. Allen <jra@nella.org>
Wed, 18 Dec 2013 20:38:53 +0000 (15:38 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 18 Dec 2013 20:38:53 +0000 (15:38 -0500)
commit17dc712c18fdba4bc88fe5adf56c3ace86c765ad
tree79162ee69c71b4c458a0aadc9817abaf428d4c27
parent3d2c4df983a1594616da94f166b16d019a487456
math/rand: Float32/64 must only return values in [0,1)

Float32 and Float64 are now both created by taking the ratio
of two integers which are chosen to fit entirely into the
precision of the desired float type. The previous code
could cast a Float64 with more than 23 bits of ".99999"
into a Float32 of 1.0, which is not in [0,1).

Float32 went from 15 to 21 ns/op (but is now correct).

Fixes #6721.

R=golang-dev, iant, rsc
CC=golang-dev
https://golang.org/cl/22730043
src/pkg/math/rand/example_test.go
src/pkg/math/rand/rand.go
src/pkg/math/rand/rand_test.go