Trait hyperdual::Num

source ·
pub trait Num: PartialEq<Self> + Zero + One + NumOps<Self, Self> {
    type FromStrRadixErr;

    // Required method
    fn from_str_radix(
        str: &str,
        radix: u32
    ) -> Result<Self, Self::FromStrRadixErr>;
}
Expand description

The base trait for numeric types, covering 0 and 1 values, comparisons, basic numeric operations, and string conversion.

Required Associated Types§

Required Methods§

source

fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>

Convert from a string and radix (typically 2..=36).

Examples
use num_traits::Num;

let result = <i32 as Num>::from_str_radix("27", 10);
assert_eq!(result, Ok(27));

let result = <i32 as Num>::from_str_radix("foo", 10);
assert!(result.is_err());
Supported radices

The exact range of supported radices is at the discretion of each type implementation. For primitive integers, this is implemented by the inherent from_str_radix methods in the standard library, which panic if the radix is not in the range from 2 to 36. The implementation in this crate for primitive floats is similar.

For third-party types, it is suggested that implementations should follow suit and at least accept 2..=36 without panicking, but an Err may be returned for any unsupported radix. It’s possible that a type might not even support the common radix 10, nor any, if string parsing doesn’t make sense for that type.

Implementations on Foreign Types§

source§

impl Num for i128

source§

impl Num for u16

source§

impl Num for u128

source§

impl Num for i64

source§

impl Num for f32

source§

impl Num for i32

source§

impl Num for f64

source§

impl Num for i8

source§

impl Num for i16

source§

impl Num for u8

source§

impl Num for usize

source§

impl Num for u64

source§

impl<T> Num for Wrapping<T>where T: Num, Wrapping<T>: NumOps<Wrapping<T>, Wrapping<T>>,

source§

impl Num for isize

source§

impl Num for u32

§

impl Num for AutoSimd<[u32; 4]>

§

type FromStrRadixErr = <u32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u32; 4]>, <AutoSimd<[u32; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u128; 1]>

§

type FromStrRadixErr = <u128 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u128; 1]>, <AutoSimd<[u128; 1]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i64; 4]>

§

type FromStrRadixErr = <i64 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i64; 4]>, <AutoSimd<[i64; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i32; 8]>

§

type FromStrRadixErr = <i32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i32; 8]>, <AutoSimd<[i32; 8]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[f32; 8]>

§

type FromStrRadixErr = <f32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[f32; 8]>, <AutoSimd<[f32; 8]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i32; 4]>

§

type FromStrRadixErr = <i32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i32; 4]>, <AutoSimd<[i32; 4]> as Num>::FromStrRadixErr>

§

impl Num for WideF64x4

§

type FromStrRadixErr = <f64 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<WideF64x4, <WideF64x4 as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u16; 8]>

§

type FromStrRadixErr = <u16 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u16; 8]>, <AutoSimd<[u16; 8]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u32; 8]>

§

type FromStrRadixErr = <u32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u32; 8]>, <AutoSimd<[u32; 8]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[f64; 8]>

§

type FromStrRadixErr = <f64 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[f64; 8]>, <AutoSimd<[f64; 8]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u16; 2]>

§

type FromStrRadixErr = <u16 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u16; 2]>, <AutoSimd<[u16; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[isize; 2]>

§

type FromStrRadixErr = <isize as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[isize; 2]>, <AutoSimd<[isize; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i64; 8]>

§

type FromStrRadixErr = <i64 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i64; 8]>, <AutoSimd<[i64; 8]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u8; 2]>

§

type FromStrRadixErr = <u8 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u8; 2]>, <AutoSimd<[u8; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u16; 32]>

§

type FromStrRadixErr = <u16 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u16; 32]>, <AutoSimd<[u16; 32]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u32; 2]>

§

type FromStrRadixErr = <u32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u32; 2]>, <AutoSimd<[u32; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u8; 8]>

§

type FromStrRadixErr = <u8 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u8; 8]>, <AutoSimd<[u8; 8]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u8; 4]>

§

type FromStrRadixErr = <u8 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u8; 4]>, <AutoSimd<[u8; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u128; 2]>

§

type FromStrRadixErr = <u128 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u128; 2]>, <AutoSimd<[u128; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i16; 4]>

§

type FromStrRadixErr = <i16 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i16; 4]>, <AutoSimd<[i16; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i64; 2]>

§

type FromStrRadixErr = <i64 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i64; 2]>, <AutoSimd<[i64; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[usize; 8]>

§

type FromStrRadixErr = <usize as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[usize; 8]>, <AutoSimd<[usize; 8]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i16; 16]>

§

type FromStrRadixErr = <i16 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i16; 16]>, <AutoSimd<[i16; 16]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u8; 32]>

§

type FromStrRadixErr = <u8 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u8; 32]>, <AutoSimd<[u8; 32]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i16; 2]>

§

type FromStrRadixErr = <i16 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i16; 2]>, <AutoSimd<[i16; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i8; 2]>

§

type FromStrRadixErr = <i8 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i8; 2]>, <AutoSimd<[i8; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[f32; 16]>

§

type FromStrRadixErr = <f32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[f32; 16]>, <AutoSimd<[f32; 16]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u16; 16]>

§

type FromStrRadixErr = <u16 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u16; 16]>, <AutoSimd<[u16; 16]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i8; 16]>

§

type FromStrRadixErr = <i8 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i8; 16]>, <AutoSimd<[i8; 16]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[isize; 4]>

§

type FromStrRadixErr = <isize as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[isize; 4]>, <AutoSimd<[isize; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i8; 32]>

§

type FromStrRadixErr = <i8 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i8; 32]>, <AutoSimd<[i8; 32]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[f64; 2]>

§

type FromStrRadixErr = <f64 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[f64; 2]>, <AutoSimd<[f64; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i16; 8]>

§

type FromStrRadixErr = <i16 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i16; 8]>, <AutoSimd<[i16; 8]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[usize; 4]>

§

type FromStrRadixErr = <usize as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[usize; 4]>, <AutoSimd<[usize; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u32; 16]>

§

type FromStrRadixErr = <u32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u32; 16]>, <AutoSimd<[u32; 16]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u64; 2]>

§

type FromStrRadixErr = <u64 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u64; 2]>, <AutoSimd<[u64; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i128; 1]>

§

type FromStrRadixErr = <i128 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i128; 1]>, <AutoSimd<[i128; 1]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i16; 32]>

§

type FromStrRadixErr = <i16 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i16; 32]>, <AutoSimd<[i16; 32]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u64; 8]>

§

type FromStrRadixErr = <u64 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u64; 8]>, <AutoSimd<[u64; 8]> as Num>::FromStrRadixErr>

§

impl Num for WideF32x4

§

type FromStrRadixErr = <f32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<WideF32x4, <WideF32x4 as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u128; 4]>

§

type FromStrRadixErr = <u128 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u128; 4]>, <AutoSimd<[u128; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[f64; 4]>

§

type FromStrRadixErr = <f64 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[f64; 4]>, <AutoSimd<[f64; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i32; 2]>

§

type FromStrRadixErr = <i32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i32; 2]>, <AutoSimd<[i32; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i8; 8]>

§

type FromStrRadixErr = <i8 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i8; 8]>, <AutoSimd<[i8; 8]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[isize; 8]>

§

type FromStrRadixErr = <isize as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[isize; 8]>, <AutoSimd<[isize; 8]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[usize; 2]>

§

type FromStrRadixErr = <usize as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[usize; 2]>, <AutoSimd<[usize; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i128; 2]>

§

type FromStrRadixErr = <i128 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i128; 2]>, <AutoSimd<[i128; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i128; 4]>

§

type FromStrRadixErr = <i128 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i128; 4]>, <AutoSimd<[i128; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i8; 4]>

§

type FromStrRadixErr = <i8 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i8; 4]>, <AutoSimd<[i8; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u8; 16]>

§

type FromStrRadixErr = <u8 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u8; 16]>, <AutoSimd<[u8; 16]> as Num>::FromStrRadixErr>

§

impl Num for WideF32x8

§

type FromStrRadixErr = <f32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<WideF32x8, <WideF32x8 as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[f32; 2]>

§

type FromStrRadixErr = <f32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[f32; 2]>, <AutoSimd<[f32; 2]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[f32; 4]>

§

type FromStrRadixErr = <f32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[f32; 4]>, <AutoSimd<[f32; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u64; 4]>

§

type FromStrRadixErr = <u64 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u64; 4]>, <AutoSimd<[u64; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[u16; 4]>

§

type FromStrRadixErr = <u16 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[u16; 4]>, <AutoSimd<[u16; 4]> as Num>::FromStrRadixErr>

§

impl Num for AutoSimd<[i32; 16]>

§

type FromStrRadixErr = <i32 as Num>::FromStrRadixErr

§

fn from_str_radix( str: &str, radix: u32 ) -> Result<AutoSimd<[i32; 16]>, <AutoSimd<[i32; 16]> as Num>::FromStrRadixErr>

source§

impl<T> Num for Complex<T>where T: Num + Clone,

source§

fn from_str_radix( s: &str, radix: u32 ) -> Result<Complex<T>, <Complex<T> as Num>::FromStrRadixErr>

Parses a +/- bi; ai +/- b; a; or bi where a and b are of type T

radix must be <= 18; larger radix would include i and j as digits, which cannot be supported.

The conversion returns an error if 18 <= radix <= 36; it panics if radix > 36.

The elements of T are parsed using Num::from_str_radix too, and errors (or panics) from that are reflected here as well.

§

type FromStrRadixErr = ParseComplexError<<T as Num>::FromStrRadixErr>

source§

impl<T> Num for Ratio<T>where T: Clone + Integer,

source§

fn from_str_radix(s: &str, radix: u32) -> Result<Ratio<T>, ParseRatioError>

Parses numer/denom where the numbers are in base radix.

§

type FromStrRadixErr = ParseRatioError

Implementors§

source§

impl<T: Copy + Scalar + Num, N: Dim + DimName> Num for OHyperdual<T, N>where DefaultAllocator: Allocator<T, N>, Owned<T, N>: Copy,