plutus-tx-1.34.0.0: Libraries for Plutus Tx and its prelude
Safe HaskellSafe-Inferred
LanguageHaskell2010

PlutusTx.Ratio

Synopsis

Type

data Rational Source #

Represents an arbitrary-precision ratio.

The following two invariants are maintained:

  1. The denominator is greater than zero.
  2. The numerator and denominator are coprime.

Instances

Instances details
FromJSON Rational Source #

This mimics the behaviour of Aeson's instance for Rational.

Instance details

Defined in PlutusTx.Ratio

Methods

parseJSON ∷ Value → Parser Rational

parseJSONList ∷ Value → Parser [Rational]

omittedFieldMaybe Rational

ToJSON Rational Source #

This mimics the behaviour of Aeson's instance for Rational.

Instance details

Defined in PlutusTx.Ratio

Methods

toJSONRational → Value

toEncodingRational → Encoding

toJSONList ∷ [Rational] → Value

toEncodingList ∷ [Rational] → Encoding

omitFieldRationalBool

Generic Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Associated Types

type Rep RationalTypeType Source #

Show Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Eq Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Ord Rational Source # 
Instance details

Defined in PlutusTx.Ratio

HasBlueprintDefinition Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Associated Types

type Unroll Rational ∷ [Type] Source #

Eq Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Methods

(==)RationalRationalBool Source #

FromData Rational Source # 
Instance details

Defined in PlutusTx.Ratio

ToData Rational Source # 
Instance details

Defined in PlutusTx.Ratio

UnsafeFromData Rational Source # 
Instance details

Defined in PlutusTx.Ratio

AdditiveGroup Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Methods

(-)RationalRationalRational Source #

AdditiveMonoid Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Methods

zeroRational Source #

AdditiveSemigroup Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Methods

(+)RationalRationalRational Source #

MultiplicativeMonoid Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Methods

oneRational Source #

MultiplicativeSemigroup Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Methods

(*)RationalRationalRational Source #

Ord Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Pretty Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Methods

prettyRationalDoc ann Source #

prettyList ∷ [Rational] → Doc ann Source #

HasSchemaDefinition Integer referencedTypes ⇒ HasBlueprintSchema Rational referencedTypes Source # 
Instance details

Defined in PlutusTx.Ratio

Methods

schemaSchema referencedTypes Source #

Lift DefaultUni Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Module Integer Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Methods

scaleIntegerRationalRational Source #

Typeable DefaultUni Rational Source # 
Instance details

Defined in PlutusTx.Ratio

type Rep Rational Source # 
Instance details

Defined in PlutusTx.Ratio

type Unroll Rational Source # 
Instance details

Defined in PlutusTx.Ratio

Construction

unsafeRatioIntegerIntegerRational Source #

Makes a Rational from a numerator and a denominator.

Important note

If given a zero denominator, this function will error. If you don't mind a size increase, and care about safety, use ratio instead.

fromIntegerIntegerRational Source #

Converts an Integer into the equivalent Rational.

ratioIntegerIntegerMaybe Rational Source #

Safely constructs a Rational from a numerator and a denominator. Returns Nothing if given a zero denominator.

Other functionality

numeratorRationalInteger Source #

Returns the numerator of its argument.

Note

It is not true in general that numerator <$> ratio x y = x; this will only hold if x and y are coprime. This is due to Rational normalizing the numerator and denominator.

denominatorRationalInteger Source #

Returns the denominator of its argument. This will always be greater than, or equal to, 1, although the type does not describe this.

Note

It is not true in general that denominator <$> ratio x y = y; this will only hold if x and y are coprime. This is due to Rational normalizing the numerator and denominator.

roundRationalInteger Source #

round r returns the nearest Integer value to r. If r is equidistant between two values, the even value will be given.

truncateRationalInteger Source #

Returns the whole-number part of its argument, dropping any leftover fractional part. More precisely, truncate r = n where (n, _) = properFraction r, but is much more efficient.

properFractionRational → (Integer, Rational) Source #

properFraction r returns the pair (n, f), such that all of the following hold:

recipRationalRational Source #

Gives the reciprocal of the argument; specifically, for r /= zero, r * recip r = one.

Important note

The reciprocal of zero is mathematically undefined; thus, recip zero will error. Use with care.

absRationalRational Source #

Returns the absolute value of its argument.

Note

This is specialized for Rational; use this instead of the generic version in PlutusTx.Numeric, as said generic version produces much larger on-chain code than the specialized version here.

negateRationalRational Source #

Produces the additive inverse of its argument.

Note

This is specialized for Rational; use this instead of the generic version of this function, as it is significantly smaller on-chain.

fromGHCRationalRational Source #

Converts a GHC Rational, preserving value. Does not work on-chain.

toGHCRationalRational Source #

Converts a Rational to a GHC Rational, preserving value. Does not work on-chain.

gcdIntegerIntegerInteger Source #

gcd x y is the non-negative factor of both x and y of which every common factor of x and y is also a factor; for example gcd 4 2 = 2, gcd (-4) 6 = 2, gcd 0 4 = 4. gcd 0 0 = 0.