mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
use num traits
This commit is contained in:
parent
646b7947e9
commit
cddb85df05
|
@ -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 }
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in a new issue