Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3752)

Issue 22730043: code review 22730043: math/rand: Float32/64 must only return values in [0,1) (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 5 months ago by jeff.allen
Modified:
10 years, 4 months ago
Reviewers:
rsc
CC:
golang-dev, iant, rsc
Visibility:
Public.

Description

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 issue 6721.

Patch Set 1 #

Patch Set 2 : diff -r 0685a9549d5a https://code.google.com/p/go #

Patch Set 3 : diff -r 0685a9549d5a https://code.google.com/p/go #

Patch Set 4 : diff -r 0685a9549d5a https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+22 lines, -4 lines) Patch
M src/pkg/math/rand/example_test.go View 1 1 chunk +2 lines, -2 lines 0 comments Download
M src/pkg/math/rand/rand.go View 1 1 chunk +2 lines, -2 lines 0 comments Download
M src/pkg/math/rand/rand_test.go View 1 2 3 2 chunks +18 lines, -0 lines 0 comments Download

Messages

Total messages: 4
jeff.allen
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go
10 years, 5 months ago (2013-11-07 08:53:59 UTC) #1
iant
Thanks. Please ping this patch after the 1.2 release.
10 years, 5 months ago (2013-11-07 14:53:45 UTC) #2
rsc
LGTM
10 years, 4 months ago (2013-12-18 20:28:35 UTC) #3
rsc
10 years, 4 months ago (2013-12-18 20:40:50 UTC) #4
*** Submitted as https://code.google.com/p/go/source/detail?r=3ed9d5c72102 ***

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 issue 6721.

R=golang-dev, iant, rsc
CC=golang-dev
https://codereview.appspot.com/22730043

Committer: Russ Cox <rsc@golang.org>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b