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

Linear ranges don't produce large values #528

Open
DigitalBrains1 opened this issue May 12, 2024 · 1 comment
Open

Linear ranges don't produce large values #528

DigitalBrains1 opened this issue May 12, 2024 · 1 comment

Comments

@DigitalBrains1
Copy link

DigitalBrains1 commented May 12, 2024

I don't think PR #405 achieved the intended result. It was intended to make the maximum value occur more often, but instead, for larger values, it does not occur at all anymore. Large numbers are 1% too small, getting worse the larger the range is.

With commit 0371468, the parent of PR #405, we see this behaviour:

$ cabal repl -w ghc-8.10 hedgehog
[...]
>>> import Hedgehog.Internal.Range
>>> import Data.Int
>>> scaleLinear 99 0 4 :: Integer
4
>>> bounds 99 (linearBounded :: Range Int8)
(-128,127)
>>> scaleLinear 99 0 100 :: Integer
100
>>> scaleLinear 99 0 10000 :: Integer
10000

I picked the 4 because that is used in the PR, and the Int8 is from the Haddock for Hedgehog, with the Haddock still to this day noting this unsurprising result of (-128,127).

WIth commit 06eb474, that is the merge of the PR, this becomes:

>>> scaleLinear 99 0 4 :: Integer
4
>>> bounds 99 (linearBounded :: Range Int8)
(-127,126)
>>> scaleLinear 99 0 100 :: Integer
99
>>> scaleLinear 99 0 10000 :: Integer
9900

Before PR #405, the code used to multiply by 99 and divide by 99.

The new code adds a constant, multiplies by 99 and divides by 100. But there is no constant additive value that can compensate for the larger division; as values get larger the division will dominate more and more. If an addition is wanted, it will need to be proportional to the values involved.

moodmosaic referenced this issue May 25, 2024
* Improve the distribution of scaleLinear

* Style nits (STYLE_GUIDE.md)

Co-authored-by: Nikos Baxevanis <nikos.baxevanis@gmail.com>
@moodmosaic
Copy link
Member

Thank you, @DigitalBrains1. This is interesting. I commented in 06eb474#r142392749.

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

No branches or pull requests

2 participants