Skip to content

Commit e97010e

Browse files
committed
num! macro uses const implementation of from_as_i32 making it fully const
1 parent 6625918 commit e97010e

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

agb-fixnum/src/num.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,22 @@ mod lut {
2121
#[macro_export]
2222
macro_rules! num {
2323
($value:expr) => {
24-
$crate::Num::new_from_parts(
25-
const {
26-
use $crate::__private::const_soft_float::soft_f64::SoftF64;
24+
const {
25+
$crate::Num::new_from_parts(
26+
const {
27+
use $crate::__private::const_soft_float::soft_f64::SoftF64;
2728

28-
let v = SoftF64($value as f64);
29-
let integer = v.trunc().to_f64();
30-
let fractional = v.sub(v.trunc()).to_f64() * (1_u64 << 30) as f64;
29+
let v = SoftF64($value as f64);
30+
let integer = v.trunc().to_f64();
31+
let fractional = v.sub(v.trunc()).to_f64() * (1_u64 << 30) as f64;
3132

32-
let integer = integer as i32;
33-
let fractional = fractional as i32;
33+
let integer = integer as i32;
34+
let fractional = fractional as i32;
3435

35-
(integer, fractional)
36-
},
37-
)
36+
(integer, fractional)
37+
},
38+
)
39+
}
3840
};
3941
}
4042

@@ -528,8 +530,11 @@ impl<I: FixedWidthUnsignedInteger, const N: usize> Num<I, N> {
528530
#[doc(hidden)]
529531
#[inline(always)]
530532
#[must_use]
531-
pub fn new_from_parts(num: (i32, i32)) -> Self {
532-
Self(I::from_as_i32(((num.0) << N) + (num.1 >> (30 - N))))
533+
pub const fn new_from_parts(num: (i32, i32)) -> Self {
534+
let (integer, fractional) = num;
535+
Self(crate::from_as_i32::<I>(
536+
(integer << N) + (fractional >> (30 - N)),
537+
))
533538
}
534539
}
535540

0 commit comments

Comments
 (0)