Does Haskell provide any constants for knowing the limits of Int
? I understand Int
is platform-dependent, but nevertheless I would like to utilize it and to initialize some values at the extremes in my particular case. The equivalent constants (for instance) in C would be INT_MAX
and INT_MIN
.
What's the difference between Integer and Int ? Integer can represent arbitrarily large integers, up to using all of the storage on your machine. Int can only represent integers in a finite range.
Being a signed data type, it can store positive values as well as negative values. Takes a size of 32 bits where 1 bit is used to store the sign of the integer. A maximum integer value that can be stored in an int data type is typically 2, 147, 483, 647, around 231 – 1, but is compiler dependent.
The maximum and minimum bounds for different types are accessed via the Bounded
type-class using the values minBound
and maxBound
.
The values are polymorphic based on the context they are in, so in some cases you might have to explicitly indicate the type if the compiler is unable to infer it. E.g.
x = minBound :: Int
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With