glados-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Common.Type.Integer

Synopsis

Documentation

data IntValue Source #

Instances

Instances details
Show IntValue Source # 
Instance details

Defined in Common.Type.Integer

Eq IntValue Source # 
Instance details

Defined in Common.Type.Integer

Ord IntValue Source # 
Instance details

Defined in Common.Type.Integer

intValueToInt :: IntValue -> Int Source #

Converts an IntValue to a standard Haskell Int.

@args - v: The IntValue to convert.

@details This function handles all IntValue constructors, converting them to the system's native Int type. Note that converting large 64-bit values on a 32-bit system might cause overflow, though this is rare in modern environments.

@return The integer value as an Int.

fitInteger :: Integer -> IntValue Source #

Converts an arbitrary Integer to the smallest suitable IntValue.

@args - n: The Integer to compress.

@details Similar to fromInt64 but works on arbitrary precision Integers. It attempts to fit the value into I8UI8, then I16UI16, etc. If the value exceeds the signed 64-bit range but fits in unsigned 64-bit, it uses UI64.

@return The optimized IntValue.

toInt64 :: IntValue -> Int64 Source #

Converts an IntValue to a standard Haskell Int64.

@args - v: The IntValue to convert.

@details Provides a safe conversion to Int64 for all underlying types. Unsigned 64-bit values are treated as signed (wrapping) if they exceed 'maxBound :: Int64'.

@return The integer value as an Int64.

fromInt64 :: Int64 -> IntValue Source #

Converts an Int64 to the smallest suitable IntValue representation.

@args - n: The Int64 value to compress.

@details This function checks the bounds of the integer to determine the most compact storage format (I8, UI8, I16, etc.). It prioritizes signed representation for small positive numbers but will use unsigned types if it saves space (e.g., 200 fits in UI8 but requires I16).

@return An IntValue wrapping the value in the smallest possible container.