Skip to content

Commit 0d8723e

Browse files
author
Dániel Buga
committed
Add methods to RMode
1 parent 7767dac commit 0d8723e

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

src/register/fpscr.rs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@ pub struct Fpscr {
77
bits: u32,
88
}
99

10-
/// Rounding mode
11-
#[derive(Clone, Copy, Debug)]
12-
pub enum RMode {
13-
/// Round to Nearest (RN) mode. This is the reset value.
14-
Nearest,
15-
/// Round towards Plus Infinity (RP) mode.
16-
PlusInfinity,
17-
/// Round towards Minus Infinity (RM) mode.
18-
MinusInfinity,
19-
/// Round towards Zero (RZ) mode.
20-
Zero,
21-
}
22-
2310
impl Fpscr {
2411
/// Creates a `Fspcr` value from raw bits.
2512
#[inline]
@@ -251,6 +238,45 @@ impl Fpscr {
251238
}
252239
}
253240

241+
/// Rounding mode
242+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
243+
pub enum RMode {
244+
/// Round to Nearest (RN) mode. This is the reset value.
245+
Nearest,
246+
/// Round towards Plus Infinity (RP) mode.
247+
PlusInfinity,
248+
/// Round towards Minus Infinity (RM) mode.
249+
MinusInfinity,
250+
/// Round towards Zero (RZ) mode.
251+
Zero,
252+
}
253+
254+
impl RMode {
255+
/// Is Nearest the current rounding mode?
256+
#[inline]
257+
fn is_nearest(self) -> bool {
258+
self == RMode::Nearest
259+
}
260+
261+
/// Is Plus Infinity the current rounding mode?
262+
#[inline]
263+
fn is_plus_infinity(self) -> bool {
264+
self == RMode::PlusInfinity
265+
}
266+
267+
/// Is Minus Infinity the current rounding mode?
268+
#[inline]
269+
fn is_minus_infinity(self) -> bool {
270+
self == RMode::MinusInfinity
271+
}
272+
273+
/// Is Zero the current rounding mode?
274+
#[inline]
275+
fn is_zero(self) -> bool {
276+
self == RMode::Zero
277+
}
278+
}
279+
254280
/// Read the FPSCR register
255281
#[inline]
256282
pub fn read() -> Fpscr {

0 commit comments

Comments
 (0)