int-conv: Direct conversion functions between Ints and Words

[ bsd3, data, library ] [ Propose Tags ] [ Report a vulnerability ]

This library defines a complete collection of conversion functions between machine integers: wordToWord32, word32ToWord64 etc.

All these functions behave like fromIntegral, but avoid going through Integer. (GHC has a specific optimisation to remove an intermediate Integer from fromIntegral conversions, but if we can be explicit, and wont need to rely on an optimisation, why wouldn't we?)

There are also conversion to/from Char. Convertions to Char are unsafe, as these allow to create invalid Char values (negative, or larger then maximum codepoint). In particular intToChar is not the same as chr; chr performs bounds check; intToChar doesn't. Conversion from Char are equivalent to fromIntegral . ord. Conversion to Char are equivalent to intToChar . fromIntegral, which does not perform bounds checks.

Only GHC>=9.4 is supported, as the primitive integers had been reworked in GHC-9.4.

This package deliberately doesn't provide any abstraction over the conversion functions.

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 1.0
Dependencies base (>=4.17.2.1 && <4.22) [details]
Tested with ghc ==9.4.8 || ==9.6.6 || ==9.8.4 || ==9.10.1 || ==9.12.1
License BSD-3-Clause
Author Oleg Grenrus
Maintainer Oleg Grenrus <oleg.grenrus@iki.fi>
Category Data
Home page https://github.com/phadej/int-conv
Source repo head: git clone https://github.com/phadej/int-conv.git
Uploaded by phadej at 2025-02-02T17:19:43Z
Distributions
Downloads 13 total (13 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2025-02-02 [all 1 reports]