Skip to content

fromIntegral (2^64 :: Integer) == (0 :: Natural)

Summary

powModNatural returns a wrong answer.

Steps to reproduce

import Data.Bits
import GHC.Natural

main = print $ powModNatural 0 (fromIntegral n) 2
  where
    n = 1 `shiftL` 64 :: Integer
    {-# NOINLINE n #-}
$ ghc -O1 powmod.hs && ./powmod
[1 of 1] Compiling Main             ( powmod.hs, powmod.o )
Linking powmod ...
1

Expected behavior

Expected answer is 0. Removing NOINLINE, changing fromIntegral to fromInteger, or switching to -O0 all rectify the situation.

Environment

  • GHC version used: 9.0.1

Optional:

  • Operating System: MacOS
  • System Architecture: x64
Edited by Bodigrim
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information