aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2026-02-22 22:39:53 +1100
committerJustin Bedo <cu@cua0.org>2026-02-22 23:12:02 +1100
commita1248d498af178340b852738f6c41fede337e1d4 (patch)
tree54e44302faad1bcc0dcff94c19f3070bd43f0d2c /src
parent155a390d1b6c9a5e84aa462a9dd8e1ea27345684 (diff)
uniform: ensure open boundsHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/PPL/Distr.hs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/PPL/Distr.hs b/src/PPL/Distr.hs
index cd8f029..d265f05 100644
--- a/src/PPL/Distr.hs
+++ b/src/PPL/Distr.hs
@@ -3,6 +3,7 @@
{-# LANGUAGE ViewPatterns #-}
module PPL.Distr where
+import Debug.Trace
import Data.Bits (countLeadingZeros, countTrailingZeros, shiftL, shiftR, (.&.))
import Data.Functor ((<&>))
@@ -105,9 +106,9 @@ geom p = first 0 <$> iid (bern p)
uniform :: Prob Double
uniform = do
z <- unbounded
- let r = countTrailingZeros z - 11
+ let r = countTrailingZeros z - 12
e <- if r >= 0 then countTrailingZeros <$> unbounded else pure r
- pure . unsafeCoerce $ (1 + (z `shiftR` 11)) `shiftR` 1 - ((unsafeCoerce e - 1011) `shiftL` 52)
+ pure . unsafeCoerce $ z `shiftR` 12 - ((unsafeCoerce e - 1010) `shiftL` 52)
-- Uses algorithm from 10.1145/3503512
bounded :: Double -> Double -> Prob Double