pub struct NumArithmetic { /* private fields */ }
Expand description

Arithmetic on Numbers.

Unary ops

  • Unary minus is follows the equation -T == T, where T is any linear type.
  • Unary negation is only defined for Bools.

Binary ops

Binary ops fall into 3 cases: Num op T == T, T op Num == T, or T op T == T, where T is any linear type (that is, Num or tuple of linear types). T op T is assumed by default, only falling into two other cases if one of operands is known to be a number and the other is not a number.

Comparisons

Order comparisons (>, <, >=, <=) can be switched on or off. Use Self::with_comparisons() constructor to switch them on. If switched on, both arguments of the order comparison must be numbers.

Implementations§

source§

impl NumArithmetic

source

pub const fn without_comparisons() -> Self

Creates an instance of arithmetic that does not support order comparisons.

source

pub const fn with_comparisons() -> Self

Creates an instance of arithmetic that supports order comparisons.

source

pub fn unify_binary_op<Prim: PrimitiveType>( substitutions: &mut Substitutions<Prim>, context: &BinaryOpContext<Prim>, errors: OpErrors<'_, Prim>, settings: OpConstraintSettings<'_, Prim> ) -> Type<Prim>

Applies binary ops logic to unify the given LHS and RHS types. Returns the result type of the binary operation.

This logic can be reused by other TypeArithmetic implementations.

Arguments
  • settings are applied to arguments of arithmetic ops.
source

pub fn process_unary_op<Prim: WithBoolean>( substitutions: &mut Substitutions<Prim>, context: &UnaryOpContext<Prim>, errors: OpErrors<'_, Prim>, constraints: &impl Constraint<Prim> ) -> Type<Prim>

Processes a unary operation according to the numeric arithmetic rules. Returns the result type of the unary operation.

This logic can be reused by other TypeArithmetic implementations.

source

pub fn process_binary_op<Prim: WithBoolean>( substitutions: &mut Substitutions<Prim>, context: &BinaryOpContext<Prim>, errors: OpErrors<'_, Prim>, comparable_type: Option<Prim>, settings: OpConstraintSettings<'_, Prim> ) -> Type<Prim>

Processes a binary operation according to the numeric arithmetic rules. Returns the result type of the unary operation.

This logic can be reused by other TypeArithmetic implementations.

Arguments
  • If comparable_type is set to Some(_), it will be used to unify arguments of order comparisons. If comparable_type is None, order comparisons are not supported.
  • constraints are applied to arguments of arithmetic ops.

Trait Implementations§

source§

impl Clone for NumArithmetic

source§

fn clone(&self) -> NumArithmetic

Returns a copy 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 NumArithmetic

source§

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

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

impl<Val> MapPrimitiveType<Val> for NumArithmeticwhere Val: Clone + NumOps + PartialEq,

§

type Prim = Num

Types of literals output by this mapper.
source§

fn type_of_literal(&self, _: &Val) -> Self::Prim

Gets the type of the provided literal value.
source§

impl TypeArithmetic<Num> for NumArithmetic

source§

fn process_unary_op( &self, substitutions: &mut Substitutions<Num>, context: &UnaryOpContext<Num>, errors: OpErrors<'_, Num> ) -> Type<Num>

Handles a unary operation.
source§

fn process_binary_op( &self, substitutions: &mut Substitutions<Num>, context: &BinaryOpContext<Num>, errors: OpErrors<'_, Num> ) -> Type<Num>

Handles a binary operation.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.