Skip to content

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

Merged
curiousleo merged 2 commits intoidontgetoutmuch:v1.2-proposalfrom
curiousleo:fp-other-formula
Jun 22, 2020
Merged

Floating point range: new formula, special case a == b#169
curiousleo merged 2 commits intoidontgetoutmuch:v1.2-proposalfrom
curiousleo:fp-other-formula

Conversation

@curiousleo
Copy link
Copy Markdown
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
Copy Markdown
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