Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point range: new formula, special case a == b #169

Merged
merged 2 commits into from
Jun 22, 2020

Conversation

curiousleo
Copy link
Collaborator

@curiousleo curiousleo commented Jun 18, 2020

Context: https://github.com/haskell/random/pull/62/files#r439693384 (@Bodigrim).

Before:

$ stack bench random:bench --ba '--small --match pattern Float'
pure/random/Float                        mean 28.82 μs  ( +- 1.865 μs  )
pure/uniformR/unbounded/Float            mean 28.67 μs  ( +- 1.443 μs  )
pure/uniformR/floating/IO/uniformFloat01M mean 28.22 μs  ( +- 609.7 ns  )
pure/uniformR/floating/IO/uniformFloatPositive01M mean 32.64 μs  ( +- 3.938 μs  )
pure/uniformR/floating/St/uniformFloat01M mean 61.45 μs  ( +- 5.318 μs  )
pure/uniformR/floating/St/uniformFloatPositive01M mean 60.94 μs  ( +- 5.621 μs  )
pure/uniformR/floating/pure/uniformFloat01M mean 29.48 μs  ( +- 2.765 μs  )
pure/uniformR/floating/pure/uniformFloatPositive01M mean 28.54 μs  ( +- 844.5 ns  )

After:

$ stack bench random:bench --ba '--small --match pattern Float'
pure/random/Float                        mean 28.94 μs  ( +- 1.332 μs  )
pure/uniformR/unbounded/Float            mean 31.43 μs  ( +- 3.454 μs  )
pure/uniformR/floating/IO/uniformFloat01M mean 31.26 μs  ( +- 2.921 μs  )
pure/uniformR/floating/IO/uniformFloatPositive01M mean 28.23 μs  ( +- 1.441 μs  )
pure/uniformR/floating/St/uniformFloat01M mean 62.20 μs  ( +- 6.332 μs  )
pure/uniformR/floating/St/uniformFloatPositive01M mean 57.13 μs  ( +- 2.214 μs  )
pure/uniformR/floating/pure/uniformFloat01M mean 32.09 μs  ( +- 3.215 μs  )
pure/uniformR/floating/pure/uniformFloatPositive01M mean 32.14 μs  ( +- 3.269 μs  )

x * a + (1 - x) * b is slightly more numerically stable than the
previous formula.
Copy link
Owner

@idontgetoutmuch idontgetoutmuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - I assume the benchmarks will be fine - if they are then we should merge this

@curiousleo curiousleo marked this pull request as ready for review June 18, 2020 08:20
@curiousleo curiousleo merged commit 83052c1 into idontgetoutmuch:v1.2-proposal Jun 22, 2020
@curiousleo curiousleo deleted the fp-other-formula branch June 22, 2020 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants