pub trait FunctionsRealType<T: NumKernel>:
FunctionsGeneralType<T>
+ PartialEq
+ PartialEq<f64>
+ PartialOrd
+ PartialOrd<f64>
+ MulComplexRight<T>
+ One {
Show 30 methods
// Required methods
fn atan2_(self, other: &Self) -> Self;
fn ceil_(self) -> Self;
fn clamp_(self, min: &Self, max: &Self) -> Self;
fn classify_(&self) -> FpCategory;
fn copysign_(self, sign: &Self) -> Self;
fn epsilon_() -> Self;
fn exp_m1_(self) -> Self;
fn floor_(self) -> Self;
fn fract_(self) -> Self;
fn hypot_(self, other: &Self) -> Self;
fn infinity_() -> Self;
fn is_sign_negative_(&self) -> bool;
fn is_sign_positive_(&self) -> bool;
fn ln_1p_(self) -> Self;
fn neg_infinity_() -> Self;
fn max_(self, other: &Self) -> Self;
fn min_(self, other: &Self) -> Self;
fn mul_add_mul_mut_(&mut self, mul: &Self, add_mul1: &Self, add_mul2: &Self);
fn mul_sub_mul_mut_(&mut self, mul: &Self, sub_mul1: &Self, sub_mul2: &Self);
fn negative_one_() -> Self;
fn one_div_2_() -> Self;
fn round_(self) -> Self;
fn round_ties_even_(self) -> Self;
fn signum_(self) -> Self;
fn total_cmp_(&self, other: &Self) -> Ordering;
fn try_from_f64_(value: f64) -> Result<Self, TryFromf64Errors>;
fn trunc_(self) -> Self;
fn two_() -> Self;
// Provided methods
fn pi_() -> Self { ... }
fn pi_div_2_() -> Self { ... }
}
Expand description
This trait represents the functions that can be applied on real numbers.
Required Methods§
Sourcefn atan2_(self, other: &Self) -> Self
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)
Sourcefn clamp_(self, min: &Self, max: &Self) -> Self
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::{FunctionsGeneralType, 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_());
Sourcefn classify_(&self) -> FpCategory
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);
Sourcefn copysign_(self, sign: &Self) -> Self
fn copysign_(self, sign: &Self) -> Self
Returns a number with the magnitude of self
and the sign of sign
.
Sourcefn epsilon_() -> Self
fn epsilon_() -> Self
Machine epsilon value for Self
.
This is the difference between 1.0
and the next larger representable number.
Sourcefn exp_m1_(self) -> Self
fn exp_m1_(self) -> Self
Returns `e^(self) - 1`` in a way that is accurate even if the number is close to zero.
Sourcefn hypot_(self, other: &Self) -> Self
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()
.
Sourcefn is_sign_negative_(&self) -> bool
fn is_sign_negative_(&self) -> bool
Returns true
if the value is negative, −0 or NaN with a negative sign.
Sourcefn is_sign_positive_(&self) -> bool
fn is_sign_positive_(&self) -> bool
Returns true
if the value is positive, +0 or NaN with a positive sign.
Sourcefn ln_1p_(self) -> Self
fn ln_1p_(self) -> Self
Returns ln(1. + self)
(natural logarithm) more accurately than if the operations were performed separately.
Sourcefn neg_infinity_() -> Self
fn neg_infinity_() -> Self
Returns the special value representing the negative infinity.
Sourcefn mul_add_mul_mut_(&mut self, mul: &Self, add_mul1: &Self, add_mul2: &Self)
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.
Sourcefn mul_sub_mul_mut_(&mut self, mul: &Self, sub_mul1: &Self, sub_mul2: &Self)
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.
Sourcefn negative_one_() -> Self
fn negative_one_() -> Self
Build and return the (floating point) value -1. represented by the proper type.
Sourcefn one_div_2_() -> Self
fn one_div_2_() -> Self
Build and return the (floating point) value 0.5 represented by the proper type.
Sourcefn round_(self) -> Self
fn round_(self) -> Self
Rounds self
to the nearest integer, rounding half-way cases away from zero.
Sourcefn round_ties_even_(self) -> Self
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);
Sourcefn signum_(self) -> Self
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
fn total_cmp_(&self, other: &Self) -> Ordering
Sourcefn try_from_f64_(value: f64) -> Result<Self, TryFromf64Errors>
fn try_from_f64_(value: f64) -> Result<Self, TryFromf64Errors>
Try to build a Self
from a f64
.
The returned value is Ok
if the input value
is finite and can be exactly represented by T::RealType
,
otherwise the returned value is TryFromf64Errors
.
Sourcefn trunc_(self) -> Self
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);
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl FunctionsRealType<Native64> for f64
impl FunctionsRealType<Native64> for f64
Source§fn atan2_(self, other: &Self) -> Self
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 clamp_(self, min: &Self, max: &Self) -> Self
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
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
fn copysign_(self, sign: &Self) -> Self
Returns a number with the magnitude of self
and the sign of sign
.
Source§fn epsilon_() -> Self
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
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 hypot_(self, other: &Self) -> Self
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 is_sign_negative_(&self) -> bool
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
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
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
fn neg_infinity_() -> Self
Returns the special value representing the negative infinity.
Source§fn mul_add_mul_mut_(&mut self, mul: &Self, add_mul1: &Self, add_mul2: &Self)
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)
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
fn negative_one_() -> Self
Build and return the (floating point) value -1. represented by a f64
.
Source§fn one_div_2_() -> Self
fn one_div_2_() -> Self
Build and return the (floating point) value 0.5 represented by the proper type.
Source§fn round_(self) -> Self
fn round_(self) -> Self
Rounds self
to the nearest integer, rounding half-way cases away from zero.
Source§fn round_ties_even_(self) -> Self
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
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>
fn try_from_f64_(value: f64) -> Result<Self, TryFromf64Errors>
Source§fn trunc_(self) -> Self
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);