Skip to content

Commit

Permalink
Pivot on teh scaling function design
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Dec 25, 2024
1 parent 47e7f74 commit 8d53061
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/System/Random/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1469,18 +1469,14 @@ scaleFloating ::
-- ^ Value in [0, 1] range that needs to be scaled.
-> a
scaleFloating l h x =
if abs l < abs h
-- Without clamping value furthest from zero we can get into a situation where scaled value can
-- get outside of it. This is not a problem for the value closest to zero, due to the
-- conditional above.
then let !y = l + x * (h - l)
in if l < h -- `l` is closer to zero
then min y h -- `l` is the true low, ensure `y` is not higher than `h`
else max y h -- `l` is the high, ensure `y` is not lower than `h`
else let !y = h + x * (l - h)
in if l < h -- `h` is closer to zero
then max y l -- `h` is the true high, ensure `y` is not lower than `l`
else min y l -- `h` is the low, ensure `y` is not higher than `l`
if isInfinite diff
then let !y = x * l + (1 - x) * h
in max (min y (max l h)) (min l h)
else if testBit w 31

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (macOS-latest, 9.10.1)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (ubuntu-latest, lts-20)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (windows-latest, 9.10.1)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (ubuntu-latest, 9.10.1)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (ubuntu-latest, 9.2.8)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (macOS-latest, 9.2.8)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (windows-latest, 9.2.8)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (ubuntu-latest, lts-16)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (ubuntu-latest, lts-12)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (ubuntu-latest, lts-14)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (macOS-latest, 8.8.4)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (ubuntu-latest, lts-19)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (windows-latest, 8.10.7)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (macOS-latest, 8.6.5)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (ubuntu-latest, 9.0.2)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (macOS-latest, 8.4.4)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (ubuntu-latest, 8.8.4)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (macOS-latest, 8.10.7)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (windows-latest, 8.4.4)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (windows-latest, 8.6.5)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (ubuntu-latest, 8.6.5)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (windows-latest, 9.0.2)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (windows-latest, 8.8.4)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (ubuntu-latest, 8.10.7)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (macOS-latest, 9.0.2)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (ubuntu-latest, lts-18)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (ubuntu-latest, 8.4.4)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (lts-20, macos-13, 9.2.8, stack.yaml)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (ubuntu-latest, lts-21)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (ubuntu-latest, 9.4.8)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (macOS-latest, 9.4.8)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (windows-latest, 9.4.8)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (ubuntu-latest, lts-22)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (ubuntu-latest, 9.8.2)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (ubuntu-latest, 9.6.6)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (windows-latest, 9.8.2)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (macOS-latest, 9.6.6)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (windows-latest, 9.6.6)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-cabal (macOS-latest, 9.8.2)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (ubuntu-latest, lts-9)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (ubuntu-latest, lts-11)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (ubuntu-latest, nightly)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (lts-20, windows-latest, 9.2.8, stack.yaml)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (lts-21, macos-13, 9.4.8, stack.yaml)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (lts-22, macos-13, 9.6.6, stack.yaml)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (lts-21, windows-latest, 9.4.8, stack.yaml)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (lts-22, windows-latest, 9.6.6, stack.yaml)

Variable not in scope: w

Check failure on line 1475 in src/System/Random/Internal.hs

View workflow job for this annotation

GitHub Actions / CI-stack (lts-14, windows-latest, 8.6.5, stack-old.yaml)

Variable not in scope: w
then l + diff * x
else h + negate diff * x
where
!diff = h - l
{-# INLINE scaleFloating #-}

-- | Generates uniformly distributed 'Float' in the range \([0, 1]\).
Expand Down

0 comments on commit 8d53061

Please sign in to comment.