Rational

FFmpeg's AVRational: an exact fraction. Use it for time-bases, frame rates and aspect ratios. Float conversion is lossy; do all arithmetic on the rational form when possible.

Always stored normalized: reduced by gcd, denominator positive. Rational(2, 4) == Rational(1, 2).

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val den: Int
Link copied to clipboard

Reciprocal: Rational(1, 30).inverse == Rational(30, 1).

Link copied to clipboard
val num: Int

Functions

Link copied to clipboard
open operator override fun compareTo(other: Rational): Int

Exact comparison: Rational(1, 30) < Rational(1, 25).

Link copied to clipboard
operator fun div(other: Rational): Rational
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
operator fun minus(other: Rational): Rational
Link copied to clipboard
operator fun plus(other: Rational): Rational
Link copied to clipboard
operator fun times(other: Rational): Rational

operator fun times(scalar: Long): Long

scalar * num / den with a Long intermediate. Multiplies after reducing scalar against den first, so e.g. pts * Rational(1, 1_000_000) stays exact far beyond what naive scalar * num would overflow at. For timestamp conversion between two arbitrary time-bases prefer the native av_rescale_q path (128-bit).

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
operator fun unaryMinus(): Rational

Negation, widened before it negates.