ac_ffmpeg/
math.rs

1//! Common math types and functions.
2
3use std::fmt::{self, Debug, Formatter};
4
5/// A rational number represented as a fraction.
6#[derive(Copy, Clone)]
7pub struct Rational {
8    num: i32,
9    den: i32,
10}
11
12impl Rational {
13    /// Create a new rational number.
14    #[inline]
15    pub const fn new(num: i32, den: i32) -> Self {
16        Self { num, den }
17    }
18
19    /// Get the numerator.
20    #[inline]
21    pub const fn num(&self) -> i32 {
22        self.num
23    }
24
25    /// Get the denominator.
26    #[inline]
27    pub const fn den(&self) -> i32 {
28        self.den
29    }
30}
31
32impl Debug for Rational {
33    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
34        write!(f, "{}/{}", self.num, self.den)
35    }
36}