From 23bdb053e84e57f41d1e6a699d0c90303500beb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Vi=C3=B6l?= Date: Fri, 20 Aug 2021 22:44:44 +0200 Subject: [PATCH 1/2] Add scaling_factor method to FixedPoint --- src/fixed_point.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/fixed_point.rs b/src/fixed_point.rs index dcb52aa..96b6746 100644 --- a/src/fixed_point.rs +++ b/src/fixed_point.rs @@ -29,6 +29,11 @@ pub trait FixedPoint: Sized + Copy { /// ``` fn integer(&self) -> Self::T; + /// Returns the _scaling factor_ [`Fraction`] part + fn scaling_factor(&self) -> Fraction { + Self::SCALING_FACTOR + } + /// Constructs a `FixedPoint` value from _integer_ and _scaling-factor_ ([`Fraction`]) parts /// /// # Errors From 91ce1a9f06798178045d35536f61d08899b6e177 Mon Sep 17 00:00:00 2001 From: Peter Taylor Date: Sun, 12 Sep 2021 14:26:45 -0600 Subject: [PATCH 2/2] docs(fixed_point): add short example to new `scaling_factor` method --- src/fixed_point.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/fixed_point.rs b/src/fixed_point.rs index 96b6746..714aed6 100644 --- a/src/fixed_point.rs +++ b/src/fixed_point.rs @@ -30,6 +30,12 @@ pub trait FixedPoint: Sized + Copy { fn integer(&self) -> Self::T; /// Returns the _scaling factor_ [`Fraction`] part + /// + /// ```rust + /// # use embedded_time::{ rate::*}; + /// # + /// assert_eq!(Kilohertz(45_u32).scaling_factor(), Fraction::new(1_000, 1)); + /// ``` fn scaling_factor(&self) -> Fraction { Self::SCALING_FACTOR }