Native64

Struct Native64 

Source
pub struct Native64;
Expand description

Numerical kernel specifier to be used as generic argument (or associated type) in order to indicate that the floating point values that must be used are the Rust’s native f64 and/or Complex<f64>.

Trait Implementations§

Source§

impl Clone for Native64

Source§

fn clone(&self) -> Native64

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Native64

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FunctionsComplexType<Native64> for Complex<f64>

Implement the FunctionsComplexType trait for the Complex<f64> type.

Source§

fn arg_(self) -> f64

Computes the principal Arg of self.

Source§

fn new_(real_part: f64, imag_part: f64) -> Self

Creates a complex number of type T::ComplexType from its real and imaginary parts.

§Panics

In debug mode a panic! will be emitted if the real_part or the imag_part is not finite.

Source§

fn real_(&self) -> f64

Get the real part of the complex number.

Source§

fn imag_(&self) -> f64

Get the imaginary part of the complex number.

Source§

fn set_real_(&mut self, real_part: f64)

Set the value of the real part.

§Panics

In debug mode a panic! will be emitted if real_part is not finite.

Source§

fn set_imag_(&mut self, imag_part: f64)

Set the value of the imaginary part.

§Panics

In debug mode a panic! will be emitted if imaginary_part is not finite.

Source§

fn add_real_(&mut self, c: &f64)

Add the value of the the real coefficient c to real part of self.

Source§

fn add_imag_(&mut self, c: &f64)

Add the value of the the real coefficient c to imaginary part of self.

Source§

fn multiply_real_(&mut self, c: &f64)

Multiply the value of the real part by the real coefficient c.

Source§

fn multiply_imag_(&mut self, c: &f64)

Multiply the value of the imaginary part by the real coefficient c.

Source§

fn conj_(self) -> Self

Computes the complex conjugate.

Source§

fn try_from_f64_( real_part: f64, imag_part: f64, ) -> Result<Self, TryFromf64Errors>

Try to build a Self from real and imaginary parts as f64 values. The returned value is Ok if the input real_part and imag_part are finite and can be exactly represented by T::RealType, otherwise the returned value is TryFromf64Errors.

Source§

impl FunctionsRealType<Native64> for f64

Source§

fn atan2_(self, other: &Self) -> Self

Computes the four quadrant arctangent of self (y) and other (x) in radians.

  • x = 0, y = 0: 0
  • x >= 0: arctan(y/x) -> [-pi/2, pi/2]
  • y >= 0: arctan(y/x) + pi -> (pi/2, pi]
  • y < 0: arctan(y/x) - pi -> (-pi, -pi/2)
use ftl_numkernel::{FunctionsGeneralType, FunctionsRealType};

let y = 3.0_f64;
let x = -4.0_f64;
let atan2 = y.atan2_(&x);
let expected = 2.4981_f64;
assert!((atan2 - expected).abs() < 0.0001);
Source§

fn ceil_(self) -> Self

Returns the smallest integer greater than or equal to self.

Source§

fn clamp_(self, min: &Self, max: &Self) -> Self

Clamp the value within the specified bounds.

Returns max if self is greater than max, and min if self is less than min. Otherwise this returns self.

Note that this function returns NaN if the initial value was NaN as well.

§Panics

Panics if min > max, min is NaN, or max is NaN.

use ftl_numkernel::{FunctionsRealType, IsNaN};

assert!((-3.0f64).clamp_(&-2.0, &1.0) == -2.0);
assert!((0.0f64).clamp_(&-2.0, &1.0) == 0.0);
assert!((2.0f64).clamp_(&-2.0, &1.0) == 1.0);
assert!((f64::NAN).clamp_(&-2.0, &1.0).is_nan_());
Source§

fn classify_(&self) -> FpCategory

Returns the floating point category of the number. If only one property is going to be tested, it is generally faster to use the specific predicate instead.

use ftl_numkernel::FunctionsRealType;
use std::num::FpCategory;

let num = 12.4_f64;
let inf = f64::INFINITY;

assert_eq!(num.classify_(), FpCategory::Normal);
assert_eq!(inf.classify_(), FpCategory::Infinite);
Source§

fn copysign_(self, sign: &Self) -> Self

Returns a number with the magnitude of self and the sign of sign.

Source§

fn epsilon_() -> Self

Machine epsilon value for f64.

This is the difference between 1.0 and the next larger representable number.

Source§

fn exp_m1_(self) -> Self

Returns `e^(self) - 1`` in a way that is accurate even if the number is close to zero.

Source§

fn floor_(self) -> Self

Returns the largest integer smaller than or equal to self.

Source§

fn fract_(self) -> Self

Returns the fractional part of self.

Source§

fn hypot_(self, other: &Self) -> Self

Compute the distance between the origin and a point (self, other) on the Euclidean plane. Equivalently, compute the length of the hypotenuse of a right-angle triangle with other sides having length self.abs() and other.abs().

Source§

fn infinity_() -> Self

Returns the special value representing the positive infinity.

Source§

fn is_sign_negative_(&self) -> bool

Returns true if the value is negative, −0 or NaN with a negative sign.

Source§

fn is_sign_positive_(&self) -> bool

Returns true if the value is positive, +0 or NaN with a positive sign.

Source§

fn ln_1p_(self) -> Self

Returns ln(1. + self) (natural logarithm) more accurately than if the operations were performed separately.

Source§

fn neg_infinity_() -> Self

Returns the special value representing the negative infinity.

Source§

fn max_(self, other: &Self) -> Self

Computes the maximum between self and other.

Source§

fn min_(self, other: &Self) -> Self

Computes the minimum between self and other.

Source§

fn mul_add_mul_mut_(&mut self, mul: &Self, add_mul1: &Self, add_mul2: &Self)

Multiplies two products and adds them in one fused operation, rounding to the nearest with only one rounding error. a.mul_add_mul_mut_(&b, &c, &d) produces a result like &a * &b + &c * &d, but stores the result in a using its precision.

Source§

fn mul_sub_mul_mut_(&mut self, mul: &Self, sub_mul1: &Self, sub_mul2: &Self)

Multiplies two products and subtracts them in one fused operation, rounding to the nearest with only one rounding error. a.mul_sub_mul_mut_(&b, &c, &d) produces a result like &a * &b - &c * &d, but stores the result in a using its precision.

Source§

fn negative_one_() -> Self

Build and return the (floating point) value -1. represented by a f64.

Source§

fn one_div_2_() -> Self

Build and return the (floating point) value 0.5 represented by the proper type.

Source§

fn round_(self) -> Self

Rounds self to the nearest integer, rounding half-way cases away from zero.

Source§

fn round_ties_even_(self) -> Self

Returns the nearest integer to a number. Rounds half-way cases to the number with an even least significant digit.

This function always returns the precise result.

§Examples
use ftl_numkernel::FunctionsRealType;

let f = 3.3_f64;
let g = -3.3_f64;
let h = 3.5_f64;
let i = 4.5_f64;

assert_eq!(f.round_ties_even_(), 3.0);
assert_eq!(g.round_ties_even_(), -3.0);
assert_eq!(h.round_ties_even_(), 4.0);
assert_eq!(i.round_ties_even_(), 4.0);
Source§

fn signum_(self) -> Self

Computes the signum.

The returned value is:

  • 1.0 if the value is positive, +0.0 or +∞
  • −1.0 if the value is negative, −0.0 or −∞
  • NaN if the value is NaN
Source§

fn try_from_f64_(value: f64) -> Result<Self, TryFromf64Errors>

Try to build a f64 instance from a f64. The returned value is Ok if the input value is finite, otherwise the returned value is TryFromf64Errors.

Source§

fn trunc_(self) -> Self

Returns the integer part of self. This means that non-integer numbers are always truncated towards zero.

§Examples
use ftl_numkernel::FunctionsRealType;

let f = 3.7_f64;
let g = 3.0_f64;
let h = -3.7_f64;

assert_eq!(f.trunc_(), 3.0);
assert_eq!(g.trunc_(), 3.0);
assert_eq!(h.trunc_(), -3.0);
Source§

fn two_() -> Self

Build and return the (floating point) value 2. represented by a f64.

Source§

fn total_cmp_(&self, other: &Self) -> Ordering

Source§

fn pi_() -> Self

Build and return the (floating point) value π represented by the proper type.
Source§

fn pi_div_2_() -> Self

Build and return the (floating point) value π/2 represented by the proper type.
Source§

impl NumKernel for Native64

Implement the NumKernel trait for Native64

Source§

type RealType = f64

The type for a real scalar value in this numerical kernel.

Source§

type ComplexType = Complex<f64>

The type for a complex scalar value in this numerical kernel.

Source§

type RawRealType = f64

Source§

type RawComplexType = Complex<f64>

Source§

impl PartialEq for Native64

Source§

fn eq(&self, other: &Native64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Native64

Source§

fn partial_cmp(&self, other: &Native64) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl FunctionsGeneralType<Native64> for Complex<f64>

Source§

impl FunctionsGeneralType<Native64> for f64

Source§

impl MulComplexLeft<Native64> for Complex<f64>

Source§

impl MulComplexRight<Native64> for f64

Source§

impl PowTrait<Native64> for Complex<f64>

Source§

impl PowTrait<Native64> for f64

Source§

impl StructuralPartialEq for Native64

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.