mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-04-15 04:14:07 +00:00
Merge branch 'double_to_fraction' into 'main'
value: Add from_double method to convert f64 to Fraction using gst_utils See merge request gstreamer/gstreamer-rs!1707
This commit is contained in:
commit
811e9b35c0
1 changed files with 11 additions and 0 deletions
|
@ -51,6 +51,17 @@ impl Fraction {
|
|||
Rational32::approximate_float(x).map(|r| r.into())
|
||||
}
|
||||
|
||||
#[doc(alias = "gst_util_double_to_fraction")]
|
||||
pub fn from_double(x: f64) -> Self {
|
||||
skip_assert_initialized!();
|
||||
let mut numer = 0;
|
||||
let mut denom = 1;
|
||||
unsafe {
|
||||
ffi::gst_util_double_to_fraction(x, &mut numer, &mut denom);
|
||||
}
|
||||
Fraction::new(numer, denom)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn numer(&self) -> i32 {
|
||||
*self.0.numer()
|
||||
|
|
Loading…
Reference in a new issue