diff options
author | 2020-06-06 18:36:48 +0200 | |
---|---|---|
committer | 2020-06-06 18:36:48 +0200 | |
commit | 0d8723ef083cc87a217eb527218387f63de9c7ce (patch) | |
tree | db5cd95fef905eb32941e8506cfee5c81a83b352 | |
parent | 7767dac7ec005c281344a225f36870d83bc7e226 (diff) | |
download | cortex-m-0d8723ef083cc87a217eb527218387f63de9c7ce.tar.gz cortex-m-0d8723ef083cc87a217eb527218387f63de9c7ce.tar.zst cortex-m-0d8723ef083cc87a217eb527218387f63de9c7ce.zip |
Add methods to RMode
-rw-r--r-- | src/register/fpscr.rs | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/src/register/fpscr.rs b/src/register/fpscr.rs index 79ddd3b..0baac32 100644 --- a/src/register/fpscr.rs +++ b/src/register/fpscr.rs @@ -7,19 +7,6 @@ pub struct Fpscr { bits: u32, } -/// Rounding mode -#[derive(Clone, Copy, Debug)] -pub enum RMode { - /// Round to Nearest (RN) mode. This is the reset value. - Nearest, - /// Round towards Plus Infinity (RP) mode. - PlusInfinity, - /// Round towards Minus Infinity (RM) mode. - MinusInfinity, - /// Round towards Zero (RZ) mode. - Zero, -} - impl Fpscr { /// Creates a `Fspcr` value from raw bits. #[inline] @@ -251,6 +238,45 @@ impl Fpscr { } } +/// Rounding mode +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum RMode { + /// Round to Nearest (RN) mode. This is the reset value. + Nearest, + /// Round towards Plus Infinity (RP) mode. + PlusInfinity, + /// Round towards Minus Infinity (RM) mode. + MinusInfinity, + /// Round towards Zero (RZ) mode. + Zero, +} + +impl RMode { + /// Is Nearest the current rounding mode? + #[inline] + fn is_nearest(self) -> bool { + self == RMode::Nearest + } + + /// Is Plus Infinity the current rounding mode? + #[inline] + fn is_plus_infinity(self) -> bool { + self == RMode::PlusInfinity + } + + /// Is Minus Infinity the current rounding mode? + #[inline] + fn is_minus_infinity(self) -> bool { + self == RMode::MinusInfinity + } + + /// Is Zero the current rounding mode? + #[inline] + fn is_zero(self) -> bool { + self == RMode::Zero + } +} + /// Read the FPSCR register #[inline] pub fn read() -> Fpscr { |