use num traits

This commit is contained in:
Corwin 2024-03-06 17:33:34 +00:00
parent 646b7947e9
commit cddb85df05
No known key found for this signature in database
2 changed files with 7 additions and 7 deletions

View file

@ -8,4 +8,4 @@ repository = "https://github.com/agbrs/agb"
[dependencies] [dependencies]
agb_macros = { version = "0.19.1", path = "../agb-macros" } agb_macros = { version = "0.19.1", path = "../agb-macros" }
num = { version = "0.4", default-features = false } num-traits = { version = "0.2", default-features = false }

View file

@ -170,7 +170,7 @@ fixed_width_signed_integer_impl!(i32);
#[repr(transparent)] #[repr(transparent)]
pub struct Num<I: FixedWidthUnsignedInteger, const N: usize>(I); pub struct Num<I: FixedWidthUnsignedInteger, const N: usize>(I);
impl<I: FixedWidthUnsignedInteger, const N: usize> num::Zero for Num<I, N> { impl<I: FixedWidthUnsignedInteger, const N: usize> num_traits::Zero for Num<I, N> {
fn zero() -> Self { fn zero() -> Self {
Self::new(I::zero()) Self::new(I::zero())
} }
@ -180,19 +180,19 @@ impl<I: FixedWidthUnsignedInteger, const N: usize> num::Zero for Num<I, N> {
} }
} }
impl<I: FixedWidthUnsignedInteger, const N: usize> num::One for Num<I, N> { impl<I: FixedWidthUnsignedInteger, const N: usize> num_traits::One for Num<I, N> {
fn one() -> Self { fn one() -> Self {
Self::new(I::one()) Self::new(I::one())
} }
} }
impl<I: FixedWidthUnsignedInteger + num::Num, const N: usize> num::Num for Num<I, N> { impl<I: FixedWidthUnsignedInteger + num_traits::Num, const N: usize> num_traits::Num for Num<I, N> {
type FromStrRadixErr = <f64 as num::Num>::FromStrRadixErr; type FromStrRadixErr = <f64 as num_traits::Num>::FromStrRadixErr;
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> { fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
// for some reason, if I don't have this it's an error, and if I do it is unused // for some reason, if I don't have this it's an error, and if I do it is unused
#[allow(unused_imports)] #[allow(unused_imports)]
use num::traits::float::FloatCore; use num_traits::float::FloatCore;
let v: f64 = f64::from_str_radix(str, radix)?; let v: f64 = f64::from_str_radix(str, radix)?;
@ -1166,7 +1166,7 @@ mod tests {
use super::*; use super::*;
use alloc::format; use alloc::format;
use num::Num as _; use num_traits::Num as _;
#[test] #[test]
fn formats_whole_numbers_correctly() { fn formats_whole_numbers_correctly() {