smart-math-0.1: Mathematical smart constructors
Safe HaskellNone
LanguageHaskell2010

Numeric.Data.Internal.Utils

Description

Internal utils.

Synopsis

Safe modular arithmetic

checkModBound Source #

Arguments

:: (AnyUpperBounded a, Integral a, Typeable a) 
=> a

The type a whose upper bound must be large enough to accommodate modular arithmetic within modulus n. This would be a Proxy except we get a better error message for the value itself.

-> Integer

The modulus n that should satisfy n <= max(a).

-> Maybe String 

Verifies that the type A is large enough to fit the modulus. Returns Nothing if the check succeeds or a String error message if the check fails.

modSafeAdd Source #

Arguments

:: (AnyUpperBounded a, Integral a) 
=> a

x

-> a

y

-> a

n (modulus)

-> a 

Performs modular addition, accounting for rounding in the type itself.

modSafeMult Source #

Arguments

:: (AnyUpperBounded a, Integral a) 
=> a

x

-> a

y

-> a

n (modulus)

-> a 

Performs modular multiplication, accounting for rounding in the type itself.

modSafeSub Source #

Arguments

:: (AnyLowerBounded a, Integral a) 
=> a

x

-> a

y

-> a

n (modulus)

-> a 

Performs modular subtraction, accounting for rounding in the type itself.

Optics

rmatching :: (Is (ReversedOptic k) An_AffineTraversal, ReversibleOptic k) => Optic k NoIx b a t s -> s -> Either t a Source #

Reversed matching. Useful with smart-constructor optics.

Since: 0.1