Skip to main content

Abs

Trait Abs 

Source
pub trait Abs:
    Neg<Output = Self>
    + Ord
    + Zero {
    // Provided method
    fn abs(self) -> Self { ... }
}
Expand description

Absolute value of a number.

The default body compares against the additive identity and negates. Types that carry their sign separately, such as the crate’s rational types, override it with a sign field write and never touch the magnitude. This trait is deliberately not blanket-implemented: a blanket impl would make that override impossible.

Provided Methods§

Source

fn abs(self) -> Self

The absolute value of a number.

Compute the additive inverse if the number is smaller than the additive identity.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Abs for i8

Source§

fn abs(self) -> Self

§Panics

In debug builds, when called on the most negative representable value, whose absolute value does not fit in the type.

Source§

impl Abs for i16

Source§

fn abs(self) -> Self

§Panics

In debug builds, when called on the most negative representable value, whose absolute value does not fit in the type.

Source§

impl Abs for i32

Source§

fn abs(self) -> Self

§Panics

In debug builds, when called on the most negative representable value, whose absolute value does not fit in the type.

Source§

impl Abs for i64

Source§

fn abs(self) -> Self

§Panics

In debug builds, when called on the most negative representable value, whose absolute value does not fit in the type.

Source§

impl Abs for i128

Source§

fn abs(self) -> Self

§Panics

In debug builds, when called on the most negative representable value, whose absolute value does not fit in the type.

Source§

impl Abs for isize

Source§

fn abs(self) -> Self

§Panics

In debug builds, when called on the most negative representable value, whose absolute value does not fit in the type.

Implementors§

Source§

impl Abs for Zero