View Source Vtc.Utils.Rational (vtc v0.4.0)

Utilities for working with Ratio vales.

Link to this section Summary

Types

t()

The Ratio module will often convert itself to an integer value if the result would be a whole number, but otherwise return a %Ratio{} struct.

Functions

Does the divrem operation on a rational vale, returns a {whole_dividend, rational_remainder} tuple.

Rounds x based on method.

Link to this section Types

@type t() :: Ratio.t() | integer()

The Ratio module will often convert itself to an integer value if the result would be a whole number, but otherwise return a %Ratio{} struct.

This type can be used when working with such a value.

Link to this section Functions

@spec divrem(t(), t()) :: {integer(), t()}

Does the divrem operation on a rational vale, returns a {whole_dividend, rational_remainder} tuple.

Link to this function

round(x, method \\ :closest)

View Source
@spec round(t(), :closest | :floor | :ceil) :: integer()
@spec round(t(), :off) :: t()

Rounds x based on method.

arguments

Arguments

  • x: The Rational value to round.

  • method: Rounding strategy. Defaults to :closest.

    • :closest: Round the to the closet whole frame, rounding up when fractional remainder is equal to 1/2.

    • :floor: Always round down to the closest whole-frame.

    • :ciel: Always round up to the closest whole-frame.

    • :off: Pass value through without rounding.