plutus-core-1.60.0.0: Language library for Plutus Core
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.SatInt

Description

Adapted from SafeInt to perform saturating arithmetic (i.e. returning max or min bounds) instead of throwing on overflow.

This is not quite as fast as using Int or Int64 directly, but we need the safety.

Synopsis

Documentation

data SatInt #

Instances

Instances details
FromJSON SatInt # 
Instance details

Defined in Data.SatInt

Methods

parseJSON :: Value -> Parser SatInt

parseJSONList :: Value -> Parser [SatInt]

omittedField :: Maybe SatInt

ToJSON SatInt # 
Instance details

Defined in Data.SatInt

Methods

toJSON :: SatInt -> Value

toEncoding :: SatInt -> Encoding

toJSONList :: [SatInt] -> Value

toEncodingList :: [SatInt] -> Encoding

omitField :: SatInt -> Bool

Bits SatInt # 
Instance details

Defined in Data.SatInt

FiniteBits SatInt # 
Instance details

Defined in Data.SatInt

Bounded SatInt # 
Instance details

Defined in Data.SatInt

Generic SatInt # 
Instance details

Defined in Data.SatInt

Associated Types

type Rep SatInt :: Type -> Type #

Methods

from :: SatInt -> Rep SatInt x #

to :: Rep SatInt x -> SatInt #

Num SatInt #

In the Num instance, we plug in our own addition, multiplication and subtraction function that perform overflow-checking.

Instance details

Defined in Data.SatInt

Lift SatInt # 
Instance details

Defined in Data.SatInt

Methods

lift :: Quote m => SatInt -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => SatInt -> Code m SatInt #

type Rep SatInt # 
Instance details

Defined in Data.SatInt

type Rep SatInt = D1 ('MetaData "SatInt" "Data.SatInt" "plutus-core-1.60.0.0-inplace-satint" 'True) (C1 ('MetaCons "SI" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSatInt") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

unsafeToSatInt :: Int -> SatInt #

Wrap an Int as a SatInt. This is unsafe because the Int can be a result of an arbitrary potentially underflowing/overflowing operation.

fromSatInt :: forall a. Num a => SatInt -> a #

An optimized version of fromIntegral . unSatInt.

dividedBy :: SatInt -> Natural -> SatInt #

Divide a SatInt by a natural number. If the natural number is zero, return maxBound; if we're at the maximum or minimum value then leave the input unaltered. This should never throw.