aboutsummaryrefslogtreecommitdiff
path: root/src/PPL/Distr.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/PPL/Distr.hs')
-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