Skip to main content

Dyadic

Struct Dyadic 

Source
pub struct Dyadic { /* private fields */ }
Expand description

An exact dyadic rational: an arbitrary-precision integer mantissa times a power of two.

Every finite f64 converts exactly, and addition, subtraction and multiplication never round or overflow. Equality and ordering compare values, not representations.

§Examples

use implicit_predicates_oracle::Dyadic;

let tenth = Dyadic::from_f64(0.1);
let three_tenths = &(&tenth + &tenth) + &tenth;
// 0.1 + 0.1 + 0.1 is not 0.3 in binary, and the oracle sees the difference.
assert_eq!(three_tenths.sign(), 1);
assert!(three_tenths > Dyadic::from_f64(0.3));

Implementations§

Source§

impl Dyadic

Source

pub fn from_f64(x: f64) -> Dyadic

Converts a finite f64 exactly. Negative zero converts to zero.

§Panics

Panics if x is NaN or infinite.

§Examples
use implicit_predicates_oracle::Dyadic;

let two = &Dyadic::from_f64(1.0) + &Dyadic::from_f64(1.0);
assert_eq!(two, Dyadic::from_f64(2.0));
Source

pub fn sum_of(xs: &[f64]) -> Dyadic

Returns the exact sum of all the given values.

§Panics

Panics if any value is NaN or infinite.

§Examples
use implicit_predicates_oracle::Dyadic;

assert_eq!(Dyadic::sum_of(&[1.0, 2.0, 4.0]), Dyadic::from_f64(7.0));
assert!(Dyadic::sum_of(&[]).is_zero());
Source

pub fn sign(&self) -> i8

Returns -1, 0 or 1 according to the sign of the value.

§Examples
use implicit_predicates_oracle::Dyadic;

assert_eq!(Dyadic::from_f64(-3.5).sign(), -1);
assert_eq!(Dyadic::from_f64(0.0).sign(), 0);
assert_eq!(Dyadic::from_f64(3.5).sign(), 1);
Source

pub fn is_zero(&self) -> bool

Returns true if the value is exactly zero.

§Examples
use implicit_predicates_oracle::Dyadic;

assert!(Dyadic::from_f64(-0.0).is_zero());
assert!(!Dyadic::from_f64(1e-300).is_zero());

Trait Implementations§

Source§

impl Add for &Dyadic

Source§

type Output = Dyadic

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Dyadic) -> Dyadic

Performs the + operation. Read more
Source§

impl Add for Dyadic

Source§

type Output = Dyadic

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Dyadic) -> Dyadic

Performs the + operation. Read more
Source§

impl Clone for Dyadic

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Dyadic

Source§

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

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

impl Eq for Dyadic

Source§

impl Mul for &Dyadic

Source§

type Output = Dyadic

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Dyadic) -> Dyadic

Performs the * operation. Read more
Source§

impl Mul for Dyadic

Source§

type Output = Dyadic

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dyadic) -> Dyadic

Performs the * operation. Read more
Source§

impl Neg for &Dyadic

Source§

type Output = Dyadic

The resulting type after applying the - operator.
Source§

fn neg(self) -> Dyadic

Performs the unary - operation. Read more
Source§

impl Neg for Dyadic

Source§

type Output = Dyadic

The resulting type after applying the - operator.
Source§

fn neg(self) -> Dyadic

Performs the unary - operation. Read more
Source§

impl Ord for Dyadic

Source§

fn cmp(&self, other: &Dyadic) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Dyadic

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Dyadic

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 Sub for &Dyadic

Source§

type Output = Dyadic

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Dyadic) -> Dyadic

Performs the - operation. Read more
Source§

impl Sub for Dyadic

Source§

type Output = Dyadic

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Dyadic) -> Dyadic

Performs the - operation. Read more

Auto Trait Implementations§

§

impl Forget for Dyadic

§

impl Freeze for Dyadic

§

impl Move for Dyadic

§

impl RefUnwindSafe for Dyadic

§

impl Send for Dyadic

§

impl Sync for Dyadic

§

impl Unpin for Dyadic

§

impl UnsafeUnpin for Dyadic

§

impl UnwindSafe for Dyadic

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.