HORIZON HASKELLDocslts/ghc-9.14.x45dd5372026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11

Modulecrypton-2.1.7Haskell2010

Crypto.Number.Basic

  • 7 values
  • Packagecrypton-2.1.7
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause AND MIT AND ISC
  • SourceBasic.hs
valuesqrti :: Integer -> (Integer, Integer)
#

sqrti returns two integers (l,b) so that l <= sqrt i <= b. The implementation is quite naive, use an approximation for the first number and use a dichotomy algorithm to compute the bound relatively efficiently.

valuenumBytes :: Integer -> Int
#

Compute the number of bytes for an integer

Out of numBits rather than out of GMP's own count in base 256. GHC's bignum sizes a number in base two by looking at its highest limb, and in any other base -- 256 included -- by dividing the number down to nothing: on a 2048-bit modulus that is 1.65 us against 0.01, and every serialization here asks for the size before it allocates. Eight bits to the byte does the rest.