blob: 832a23b0eed5d941dbbc80e546c17710d6d7ecd3 [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `traits` mod in crate `num`."><meta name="keywords" content="rust, rustlang, rust-lang, traits"><title>num::traits - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../../num/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../num/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Module traits</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Module <a href="../index.html">num</a>::<wbr><a class="mod" href="#">traits</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/num/lib.rs.html#100">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="bounds/index.html" title="num::traits::bounds mod">bounds</a></div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="cast/index.html" title="num::traits::cast mod">cast</a></div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="float/index.html" title="num::traits::float mod">float</a></div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="identities/index.html" title="num::traits::identities mod">identities</a></div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="int/index.html" title="num::traits::int mod">int</a></div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="ops/index.html" title="num::traits::ops mod">ops</a></div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="pow/index.html" title="num::traits::pow mod">pow</a></div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="real/index.html" title="num::traits::real mod">real</a></div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="sign/index.html" title="num::traits::sign mod">sign</a></div></div></div><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.ParseFloatError.html" title="num::traits::ParseFloatError struct">ParseFloatError</a></div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.FloatErrorKind.html" title="num::traits::FloatErrorKind enum">FloatErrorKind</a></div></div></div><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.AsPrimitive.html" title="num::traits::AsPrimitive trait">AsPrimitive</a></div><div class="item-right docblock-short">A generic interface for casting between machine scalars with the
<code>as</code> operator, which admits narrowing and precision loss.
Implementers of this trait <code>AsPrimitive</code> should behave like a primitive
numeric type (e.g. a newtype around another primitive), and the
intended conversion must never fail.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Bounded.html" title="num::traits::Bounded trait">Bounded</a></div><div class="item-right docblock-short">Numbers which have upper and lower bounds</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.CheckedAdd.html" title="num::traits::CheckedAdd trait">CheckedAdd</a></div><div class="item-right docblock-short">Performs addition that returns <code>None</code> instead of wrapping around on
overflow.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.CheckedDiv.html" title="num::traits::CheckedDiv trait">CheckedDiv</a></div><div class="item-right docblock-short">Performs division that returns <code>None</code> instead of panicking on division by zero and instead of
wrapping around on underflow and overflow.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.CheckedEuclid.html" title="num::traits::CheckedEuclid trait">CheckedEuclid</a></div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.CheckedMul.html" title="num::traits::CheckedMul trait">CheckedMul</a></div><div class="item-right docblock-short">Performs multiplication that returns <code>None</code> instead of wrapping around on underflow or
overflow.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.CheckedNeg.html" title="num::traits::CheckedNeg trait">CheckedNeg</a></div><div class="item-right docblock-short">Performs negation that returns <code>None</code> if the result can’t be represented.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.CheckedRem.html" title="num::traits::CheckedRem trait">CheckedRem</a></div><div class="item-right docblock-short">Performs an integral remainder that returns <code>None</code> instead of panicking on division by zero and
instead of wrapping around on underflow and overflow.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.CheckedShl.html" title="num::traits::CheckedShl trait">CheckedShl</a></div><div class="item-right docblock-short">Performs a left shift that returns <code>None</code> on shifts larger than
the type width.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.CheckedShr.html" title="num::traits::CheckedShr trait">CheckedShr</a></div><div class="item-right docblock-short">Performs a right shift that returns <code>None</code> on shifts larger than
the type width.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.CheckedSub.html" title="num::traits::CheckedSub trait">CheckedSub</a></div><div class="item-right docblock-short">Performs subtraction that returns <code>None</code> instead of wrapping around on underflow.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Euclid.html" title="num::traits::Euclid trait">Euclid</a></div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Float.html" title="num::traits::Float trait">Float</a></div><div class="item-right docblock-short">Generic trait for floating point numbers</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.FloatConst.html" title="num::traits::FloatConst trait">FloatConst</a></div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.FromPrimitive.html" title="num::traits::FromPrimitive trait">FromPrimitive</a></div><div class="item-right docblock-short">A generic trait for converting a number to a value.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Inv.html" title="num::traits::Inv trait">Inv</a></div><div class="item-right docblock-short">Unary operator for retrieving the multiplicative inverse, or reciprocal, of a value.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.MulAdd.html" title="num::traits::MulAdd trait">MulAdd</a></div><div class="item-right docblock-short">Fused multiply-add. Computes <code>(self * a) + b</code> with only one rounding
error, yielding a more accurate result than an unfused multiply-add.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.MulAddAssign.html" title="num::traits::MulAddAssign trait">MulAddAssign</a></div><div class="item-right docblock-short">The fused multiply-add assignment operation.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Num.html" title="num::traits::Num trait">Num</a></div><div class="item-right docblock-short">The base trait for numeric types, covering <code>0</code> and <code>1</code> values,
comparisons, basic numeric operations, and string conversion.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.NumAssign.html" title="num::traits::NumAssign trait">NumAssign</a></div><div class="item-right docblock-short">The trait for <code>Num</code> types which also implement assignment operators.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.NumAssignOps.html" title="num::traits::NumAssignOps trait">NumAssignOps</a></div><div class="item-right docblock-short">Generic trait for types implementing numeric assignment operators (like <code>+=</code>).</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.NumAssignRef.html" title="num::traits::NumAssignRef trait">NumAssignRef</a></div><div class="item-right docblock-short">The trait for <code>NumAssign</code> types which also implement assignment operations
taking the second operand by reference.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.NumCast.html" title="num::traits::NumCast trait">NumCast</a></div><div class="item-right docblock-short">An interface for casting between machine scalars.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.NumOps.html" title="num::traits::NumOps trait">NumOps</a></div><div class="item-right docblock-short">Generic trait for types implementing basic numeric operations</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.NumRef.html" title="num::traits::NumRef trait">NumRef</a></div><div class="item-right docblock-short">The trait for <code>Num</code> types which also implement numeric operations taking
the second operand by reference.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.One.html" title="num::traits::One trait">One</a></div><div class="item-right docblock-short">Defines a multiplicative identity element for <code>Self</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Pow.html" title="num::traits::Pow trait">Pow</a></div><div class="item-right docblock-short">Binary operator for raising a value to a power.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.PrimInt.html" title="num::traits::PrimInt trait">PrimInt</a></div><div class="item-right docblock-short">Generic trait for primitive integers.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.RefNum.html" title="num::traits::RefNum trait">RefNum</a></div><div class="item-right docblock-short">The trait for <code>Num</code> references which implement numeric operations, taking the
second operand either by value or by reference.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Saturating.html" title="num::traits::Saturating trait">Saturating</a></div><div class="item-right docblock-short">Saturating math operations. Deprecated, use <code>SaturatingAdd</code>, <code>SaturatingSub</code> and
<code>SaturatingMul</code> instead.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.SaturatingAdd.html" title="num::traits::SaturatingAdd trait">SaturatingAdd</a></div><div class="item-right docblock-short">Performs addition that saturates at the numeric bounds instead of overflowing.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.SaturatingMul.html" title="num::traits::SaturatingMul trait">SaturatingMul</a></div><div class="item-right docblock-short">Performs multiplication that saturates at the numeric bounds instead of overflowing.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.SaturatingSub.html" title="num::traits::SaturatingSub trait">SaturatingSub</a></div><div class="item-right docblock-short">Performs subtraction that saturates at the numeric bounds instead of overflowing.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Signed.html" title="num::traits::Signed trait">Signed</a></div><div class="item-right docblock-short">Useful functions for signed numbers (i.e. numbers that can be negative).</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.ToPrimitive.html" title="num::traits::ToPrimitive trait">ToPrimitive</a></div><div class="item-right docblock-short">A generic trait for converting a value to a number.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Unsigned.html" title="num::traits::Unsigned trait">Unsigned</a></div><div class="item-right docblock-short">A trait for values which cannot be negative</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.WrappingAdd.html" title="num::traits::WrappingAdd trait">WrappingAdd</a></div><div class="item-right docblock-short">Performs addition that wraps around on overflow.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.WrappingMul.html" title="num::traits::WrappingMul trait">WrappingMul</a></div><div class="item-right docblock-short">Performs multiplication that wraps around on overflow.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.WrappingNeg.html" title="num::traits::WrappingNeg trait">WrappingNeg</a></div><div class="item-right docblock-short">Performs a negation that does not panic.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.WrappingShl.html" title="num::traits::WrappingShl trait">WrappingShl</a></div><div class="item-right docblock-short">Performs a left shift that does not panic.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.WrappingShr.html" title="num::traits::WrappingShr trait">WrappingShr</a></div><div class="item-right docblock-short">Performs a right shift that does not panic.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.WrappingSub.html" title="num::traits::WrappingSub trait">WrappingSub</a></div><div class="item-right docblock-short">Performs subtraction that wraps around on overflow.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Zero.html" title="num::traits::Zero trait">Zero</a></div><div class="item-right docblock-short">Defines an additive identity element for <code>Self</code>.</div></div></div><h2 id="functions" class="small-section-header"><a href="#functions">Functions</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.abs.html" title="num::traits::abs fn">abs</a></div><div class="item-right docblock-short">Computes the absolute value.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.abs_sub.html" title="num::traits::abs_sub fn">abs_sub</a></div><div class="item-right docblock-short">The positive difference of two numbers.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.cast.html" title="num::traits::cast fn">cast</a></div><div class="item-right docblock-short">Cast from one machine scalar to another.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.checked_pow.html" title="num::traits::checked_pow fn">checked_pow</a></div><div class="item-right docblock-short">Raises a value to the power of exp, returning <code>None</code> if an overflow occurred.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.clamp.html" title="num::traits::clamp fn">clamp</a></div><div class="item-right docblock-short">A value bounded by a minimum and a maximum</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.clamp_max.html" title="num::traits::clamp_max fn">clamp_max</a></div><div class="item-right docblock-short">A value bounded by a maximum value</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.clamp_min.html" title="num::traits::clamp_min fn">clamp_min</a></div><div class="item-right docblock-short">A value bounded by a minimum value</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.one.html" title="num::traits::one fn">one</a></div><div class="item-right docblock-short">Returns the multiplicative identity, <code>1</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.pow.html" title="num::traits::pow fn">pow</a></div><div class="item-right docblock-short">Raises a value to the power of exp, using exponentiation by squaring.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.signum.html" title="num::traits::signum fn">signum</a></div><div class="item-right docblock-short">Returns the sign of the number.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.zero.html" title="num::traits::zero fn">zero</a></div><div class="item-right docblock-short">Returns the additive identity, <code>0</code>.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="num" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>