wasmi/num_traits/float/trait.Float.html

790 lines
123 KiB
HTML
Raw Permalink Normal View History

2019-10-23 15:27:04 +00:00
<!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 `Float` trait in crate `num_traits`."><meta name="keywords" content="rust, rustlang, rust-lang, Float"><title>num_traits::float::Float - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc trait"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../../num_traits/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Trait Float</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.abs">abs</a><a href="#tymethod.abs_sub">abs_sub</a><a href="#tymethod.acos">acos</a><a href="#tymethod.acosh">acosh</a><a href="#tymethod.asin">asin</a><a href="#tymethod.asinh">asinh</a><a href="#tymethod.atan">atan</a><a href="#tymethod.atan2">atan2</a><a href="#tymethod.atanh">atanh</a><a href="#tymethod.cbrt">cbrt</a><a href="#tymethod.ceil">ceil</a><a href="#tymethod.classify">classify</a><a href="#tymethod.cos">cos</a><a href="#tymethod.cosh">cosh</a><a href="#tymethod.exp">exp</a><a href="#tymethod.exp2">exp2</a><a href="#tymethod.exp_m1">exp_m1</a><a href="#tymethod.floor">floor</a><a href="#tymethod.fract">fract</a><a href="#tymethod.hypot">hypot</a><a href="#tymethod.infinity">infinity</a><a href="#tymethod.integer_decode">integer_decode</a><a href="#tymethod.is_finite">is_finite</a><a href="#tymethod.is_infinite">is_infinite</a><a href="#tymethod.is_nan">is_nan</a><a href="#tymethod.is_normal">is_normal</a><a href="#tymethod.is_sign_negative">is_sign_negative</a><a href="#tymethod.is_sign_positive">is_sign_positive</a><a href="#tymethod.ln">ln</a><a href="#tymethod.ln_1p">ln_1p</a><a href="#tymethod.log">log</a><a href="#tymethod.log10">log10</a><a href="#tymethod.log2">log2</a><a href="#tymethod.max">max</a><a href="#tymethod.max_value">max_value</a><a href="#tymethod.min">min</a><a href="#tymethod.min_positive_value">min_positive_value</a><a href="#tymethod.min_value">min_value</a><a href="#tymethod.mul_add">mul_add</a><a href="#tymethod.nan">nan</a><a href="#tymethod.neg_infinity">neg_infinity</a><a href="#tymethod.neg_zero">neg_zero</a><a href="#tymethod.powf">powf</a><a href="#tymethod.powi">powi</a><a href="#tymethod.recip">recip</a><a href="#tymethod.round">round</a><a href="#tymethod.signum">signum</a><a href="#tymethod.sin">sin</a><a href="#tymethod.sin_cos">sin_cos</a><a href="#tymethod.sinh">sinh</a><a href="#tymethod.sqrt">sqrt</a><a href="#tymethod.tan">tan</a><a href="#tymethod.tanh">tanh</a><a href="#tymethod.trunc">trunc</a></div><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.epsilon">epsilon</a><a href="#method.to_degrees">to_degrees</a><a href="#method.to_radians">to_radians</a></div><a class="sidebar-title" href="#foreign-impls">Implementations on Foreign Types</a><div class="sidebar-links"><a href="#impl-Float-for-f32">f32</a><a href="#impl-Float-for-f64">f64</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='../index.html'>num_traits</a>::<wbr><a href='index.html'>float</a></p><script>window.sidebarCurrent = {name: 'Float', t
fn <a href='#tymethod.nan' class='fnname'>nan</a>() -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.infinity' class='fnname'>infinity</a>() -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.neg_infinity' class='fnname'>neg_infinity</a>() -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.neg_zero' class='fnname'>neg_zero</a>() -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.min_value' class='fnname'>min_value</a>() -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.min_positive_value' class='fnname'>min_positive_value</a>() -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.max_value' class='fnname'>max_value</a>() -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.is_nan' class='fnname'>is_nan</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>;
<div class='item-spacer'></div> fn <a href='#tymethod.is_infinite' class='fnname'>is_infinite</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>;
<div class='item-spacer'></div> fn <a href='#tymethod.is_finite' class='fnname'>is_finite</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>;
<div class='item-spacer'></div> fn <a href='#tymethod.is_normal' class='fnname'>is_normal</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>;
<div class='item-spacer'></div> fn <a href='#tymethod.classify' class='fnname'>classify</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/num/enum.FpCategory.html" title="enum core::num::FpCategory">FpCategory</a>;
<div class='item-spacer'></div> fn <a href='#tymethod.floor' class='fnname'>floor</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.ceil' class='fnname'>ceil</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.round' class='fnname'>round</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.trunc' class='fnname'>trunc</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.fract' class='fnname'>fract</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.abs' class='fnname'>abs</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.signum' class='fnname'>signum</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.is_sign_positive' class='fnname'>is_sign_positive</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>;
<div class='item-spacer'></div> fn <a href='#tymethod.is_sign_negative' class='fnname'>is_sign_negative</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>;
<div class='item-spacer'></div> fn <a href='#tymethod.mul_add' class='fnname'>mul_add</a>(self, a: Self, b: Self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.recip' class='fnname'>recip</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.powi' class='fnname'>powi</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.powf' class='fnname'>powf</a>(self, n: Self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.sqrt' class='fnname'>sqrt</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.exp' class='fnname'>exp</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.exp2' class='fnname'>exp2</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.ln' class='fnname'>ln</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.log' class='fnname'>log</a>(self, base: Self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.log2' class='fnname'>log2</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.log10' class='fnname'>log10</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.max' class='fnname'>max</a>(self, other: Self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.min' class='fnname'>min</a>(self, other: Self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.abs_sub' class='fnname'>abs_sub</a>(self, other: Self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.cbrt' class='fnname'>cbrt</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.hypot' class='fnname'>hypot</a>(self, other: Self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.sin' class='fnname'>sin</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.cos' class='fnname'>cos</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.tan' class='fnname'>tan</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.asin' class='fnname'>asin</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.acos' class='fnname'>acos</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.atan' class='fnname'>atan</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.atan2' class='fnname'>atan2</a>(self, other: Self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.sin_cos' class='fnname'>sin_cos</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>Self, Self<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>;
<div class='item-spacer'></div> fn <a href='#tymethod.exp_m1' class='fnname'>exp_m1</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.ln_1p' class='fnname'>ln_1p</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.sinh' class='fnname'>sinh</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.cosh' class='fnname'>cosh</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.tanh' class='fnname'>tanh</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.asinh' class='fnname'>asinh</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.acosh' class='fnname'>acosh</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.atanh' class='fnname'>atanh</a>(self) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.integer_decode' class='fnname'>integer_decode</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i16.html">i16</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i8.html">i8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>;
fn <a href='#method.epsilon' class='fnname'>epsilon</a>() -&gt; Self { ... }
<div class='item-spacer'></div> fn <a href='#method.to_degrees' class='fnname'>to_degrees</a>(self) -&gt; Self { ... }
<div class='item-spacer'></div> fn <a href='#method.to_radians' class='fnname'>to_radians</a>(self) -&gt; Self { ... }
}</pre></div><div class='docblock'><p>Generic trait for floating point numbers</p>
<p>This trait is only available with the <code>std</code> feature.</p>
</div>
<h2 id='required-methods' class='small-section-header'>Required methods<a href='#required-methods' class='anchor'></a></h2><div class='methods'><h3 id='tymethod.nan' class='method'><code id='nan.v'>fn <a href='#tymethod.nan' class='fnname'>nan</a>() -&gt; Self</code></h3><div class='docblock'><p>Returns the <code>NaN</code> value.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">nan</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">nan</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">nan</span>.<span class="ident">is_nan</span>());</pre></div>
</div><h3 id='tymethod.infinity' class='method'><code id='infinity.v'>fn <a href='#tymethod.infinity' class='fnname'>infinity</a>() -&gt; Self</code></h3><div class='docblock'><p>Returns the infinite value.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f32</span>;
<span class="kw">let</span> <span class="ident">infinity</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">infinity</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">infinity</span>.<span class="ident">is_infinite</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">infinity</span>.<span class="ident">is_finite</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">infinity</span> <span class="op">&gt;</span> <span class="ident">f32</span>::<span class="ident">MAX</span>);</pre></div>
</div><h3 id='tymethod.neg_infinity' class='method'><code id='neg_infinity.v'>fn <a href='#tymethod.neg_infinity' class='fnname'>neg_infinity</a>() -&gt; Self</code></h3><div class='docblock'><p>Returns the negative infinite value.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f32</span>;
<span class="kw">let</span> <span class="ident">neg_infinity</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">neg_infinity</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">neg_infinity</span>.<span class="ident">is_infinite</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">neg_infinity</span>.<span class="ident">is_finite</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">neg_infinity</span> <span class="op">&lt;</span> <span class="ident">f32</span>::<span class="ident">MIN</span>);</pre></div>
</div><h3 id='tymethod.neg_zero' class='method'><code id='neg_zero.v'>fn <a href='#tymethod.neg_zero' class='fnname'>neg_zero</a>() -&gt; Self</code></h3><div class='docblock'><p>Returns <code>-0.0</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::{<span class="ident">Zero</span>, <span class="ident">Float</span>};
<span class="kw">let</span> <span class="ident">inf</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">infinity</span>();
<span class="kw">let</span> <span class="ident">zero</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">Zero</span>::<span class="ident">zero</span>();
<span class="kw">let</span> <span class="ident">neg_zero</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">neg_zero</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">zero</span>, <span class="ident">neg_zero</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">7.0f32</span><span class="op">/</span><span class="ident">inf</span>, <span class="ident">zero</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">zero</span> <span class="op">*</span> <span class="number">10.0</span>, <span class="ident">zero</span>);</pre></div>
</div><h3 id='tymethod.min_value' class='method'><code id='min_value.v'>fn <a href='#tymethod.min_value' class='fnname'>min_value</a>() -&gt; Self</code></h3><div class='docblock'><p>Returns the smallest finite value that this type can represent.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">x</span>: <span class="ident">f64</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">min_value</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">x</span>, <span class="ident">f64</span>::<span class="ident">MIN</span>);</pre></div>
</div><h3 id='tymethod.min_positive_value' class='method'><code id='min_positive_value.v'>fn <a href='#tymethod.min_positive_value' class='fnname'>min_positive_value</a>() -&gt; Self</code></h3><div class='docblock'><p>Returns the smallest positive, normalized value that this type can represent.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">x</span>: <span class="ident">f64</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">min_positive_value</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">x</span>, <span class="ident">f64</span>::<span class="ident">MIN_POSITIVE</span>);</pre></div>
</div><h3 id='tymethod.max_value' class='method'><code id='max_value.v'>fn <a href='#tymethod.max_value' class='fnname'>max_value</a>() -&gt; Self</code></h3><div class='docblock'><p>Returns the largest finite value that this type can represent.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">x</span>: <span class="ident">f64</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">max_value</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">x</span>, <span class="ident">f64</span>::<span class="ident">MAX</span>);</pre></div>
</div><h3 id='tymethod.is_nan' class='method'><code id='is_nan.v'>fn <a href='#tymethod.is_nan' class='fnname'>is_nan</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></h3><div class='docblock'><p>Returns <code>true</code> if this value is <code>NaN</code> and false otherwise.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">nan</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">NAN</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">7.0</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">nan</span>.<span class="ident">is_nan</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">f</span>.<span class="ident">is_nan</span>());</pre></div>
</div><h3 id='tymethod.is_infinite' class='method'><code id='is_infinite.v'>fn <a href='#tymethod.is_infinite' class='fnname'>is_infinite</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></h3><div class='docblock'><p>Returns <code>true</code> if this value is positive infinity or negative infinity and
false otherwise.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f32</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">7.0f32</span>;
<span class="kw">let</span> <span class="ident">inf</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">infinity</span>();
<span class="kw">let</span> <span class="ident">neg_inf</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">neg_infinity</span>();
<span class="kw">let</span> <span class="ident">nan</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">f32</span>::<span class="ident">NAN</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">f</span>.<span class="ident">is_infinite</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">nan</span>.<span class="ident">is_infinite</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">inf</span>.<span class="ident">is_infinite</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">neg_inf</span>.<span class="ident">is_infinite</span>());</pre></div>
</div><h3 id='tymethod.is_finite' class='method'><code id='is_finite.v'>fn <a href='#tymethod.is_finite' class='fnname'>is_finite</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></h3><div class='docblock'><p>Returns <code>true</code> if this number is neither infinite nor <code>NaN</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f32</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">7.0f32</span>;
<span class="kw">let</span> <span class="ident">inf</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">infinity</span>();
<span class="kw">let</span> <span class="ident">neg_inf</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">neg_infinity</span>();
<span class="kw">let</span> <span class="ident">nan</span>: <span class="ident">f32</span> <span class="op">=</span> <span class="ident">f32</span>::<span class="ident">NAN</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">f</span>.<span class="ident">is_finite</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">nan</span>.<span class="ident">is_finite</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">inf</span>.<span class="ident">is_finite</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">neg_inf</span>.<span class="ident">is_finite</span>());</pre></div>
</div><h3 id='tymethod.is_normal' class='method'><code id='is_normal.v'>fn <a href='#tymethod.is_normal' class='fnname'>is_normal</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></h3><div class='docblock'><p>Returns <code>true</code> if the number is neither zero, infinite,
<a href="http://en.wikipedia.org/wiki/Denormal_number">subnormal</a>, or <code>NaN</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f32</span>;
<span class="kw">let</span> <span class="ident">min</span> <span class="op">=</span> <span class="ident">f32</span>::<span class="ident">MIN_POSITIVE</span>; <span class="comment">// 1.17549435e-38f32</span>
<span class="kw">let</span> <span class="ident">max</span> <span class="op">=</span> <span class="ident">f32</span>::<span class="ident">MAX</span>;
<span class="kw">let</span> <span class="ident">lower_than_min</span> <span class="op">=</span> <span class="number">1.0e-40_f32</span>;
<span class="kw">let</span> <span class="ident">zero</span> <span class="op">=</span> <span class="number">0.0f32</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">min</span>.<span class="ident">is_normal</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">max</span>.<span class="ident">is_normal</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">zero</span>.<span class="ident">is_normal</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">f32</span>::<span class="ident">NAN</span>.<span class="ident">is_normal</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">f32</span>::<span class="ident">INFINITY</span>.<span class="ident">is_normal</span>());
<span class="comment">// Values between `0` and `min` are Subnormal.</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">lower_than_min</span>.<span class="ident">is_normal</span>());</pre></div>
</div><h3 id='tymethod.classify' class='method'><code id='classify.v'>fn <a href='#tymethod.classify' class='fnname'>classify</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/num/enum.FpCategory.html" title="enum core::num::FpCategory">FpCategory</a></code></h3><div class='docblock'><p>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.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">num</span>::<span class="ident">FpCategory</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f32</span>;
<span class="kw">let</span> <span class="ident">num</span> <span class="op">=</span> <span class="number">12.4f32</span>;
<span class="kw">let</span> <span class="ident">inf</span> <span class="op">=</span> <span class="ident">f32</span>::<span class="ident">INFINITY</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">num</span>.<span class="ident">classify</span>(), <span class="ident">FpCategory</span>::<span class="ident">Normal</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">inf</span>.<span class="ident">classify</span>(), <span class="ident">FpCategory</span>::<span class="ident">Infinite</span>);</pre></div>
</div><h3 id='tymethod.floor' class='method'><code id='floor.v'>fn <a href='#tymethod.floor' class='fnname'>floor</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns the largest integer less than or equal to a number.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">3.99</span>;
<span class="kw">let</span> <span class="ident">g</span> <span class="op">=</span> <span class="number">3.0</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">f</span>.<span class="ident">floor</span>(), <span class="number">3.0</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">g</span>.<span class="ident">floor</span>(), <span class="number">3.0</span>);</pre></div>
</div><h3 id='tymethod.ceil' class='method'><code id='ceil.v'>fn <a href='#tymethod.ceil' class='fnname'>ceil</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns the smallest integer greater than or equal to a number.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">3.01</span>;
<span class="kw">let</span> <span class="ident">g</span> <span class="op">=</span> <span class="number">4.0</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">f</span>.<span class="ident">ceil</span>(), <span class="number">4.0</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">g</span>.<span class="ident">ceil</span>(), <span class="number">4.0</span>);</pre></div>
</div><h3 id='tymethod.round' class='method'><code id='round.v'>fn <a href='#tymethod.round' class='fnname'>round</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns the nearest integer to a number. Round half-way cases away from
<code>0.0</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">3.3</span>;
<span class="kw">let</span> <span class="ident">g</span> <span class="op">=</span> <span class="op">-</span><span class="number">3.3</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">f</span>.<span class="ident">round</span>(), <span class="number">3.0</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">g</span>.<span class="ident">round</span>(), <span class="op">-</span><span class="number">3.0</span>);</pre></div>
</div><h3 id='tymethod.trunc' class='method'><code id='trunc.v'>fn <a href='#tymethod.trunc' class='fnname'>trunc</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Return the integer part of a number.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">3.3</span>;
<span class="kw">let</span> <span class="ident">g</span> <span class="op">=</span> <span class="op">-</span><span class="number">3.7</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">f</span>.<span class="ident">trunc</span>(), <span class="number">3.0</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">g</span>.<span class="ident">trunc</span>(), <span class="op">-</span><span class="number">3.0</span>);</pre></div>
</div><h3 id='tymethod.fract' class='method'><code id='fract.v'>fn <a href='#tymethod.fract' class='fnname'>fract</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns the fractional part of a number.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">3.5</span>;
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="op">-</span><span class="number">3.5</span>;
<span class="kw">let</span> <span class="ident">abs_difference_x</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">fract</span>() <span class="op">-</span> <span class="number">0.5</span>).<span class="ident">abs</span>();
<span class="kw">let</span> <span class="ident">abs_difference_y</span> <span class="op">=</span> (<span class="ident">y</span>.<span class="ident">fract</span>() <span class="op">-</span> (<span class="op">-</span><span class="number">0.5</span>)).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_x</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_y</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.abs' class='method'><code id='abs.v'>fn <a href='#tymethod.abs' class='fnname'>abs</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Computes the absolute value of <code>self</code>. Returns <code>Float::nan()</code> if the
number is <code>Float::nan()</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">3.5</span>;
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="op">-</span><span class="number">3.5</span>;
<span class="kw">let</span> <span class="ident">abs_difference_x</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">abs</span>() <span class="op">-</span> <span class="ident">x</span>).<span class="ident">abs</span>();
<span class="kw">let</span> <span class="ident">abs_difference_y</span> <span class="op">=</span> (<span class="ident">y</span>.<span class="ident">abs</span>() <span class="op">-</span> (<span class="op">-</span><span class="ident">y</span>)).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_x</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_y</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">f64</span>::<span class="ident">NAN</span>.<span class="ident">abs</span>().<span class="ident">is_nan</span>());</pre></div>
</div><h3 id='tymethod.signum' class='method'><code id='signum.v'>fn <a href='#tymethod.signum' class='fnname'>signum</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns a number that represents the sign of <code>self</code>.</p>
<ul>
<li><code>1.0</code> if the number is positive, <code>+0.0</code> or <code>Float::infinity()</code></li>
<li><code>-1.0</code> if the number is negative, <code>-0.0</code> or <code>Float::neg_infinity()</code></li>
<li><code>Float::nan()</code> if the number is <code>Float::nan()</code></li>
</ul>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">3.5</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">f</span>.<span class="ident">signum</span>(), <span class="number">1.0</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">f64</span>::<span class="ident">NEG_INFINITY</span>.<span class="ident">signum</span>(), <span class="op">-</span><span class="number">1.0</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">f64</span>::<span class="ident">NAN</span>.<span class="ident">signum</span>().<span class="ident">is_nan</span>());</pre></div>
</div><h3 id='tymethod.is_sign_positive' class='method'><code id='is_sign_positive.v'>fn <a href='#tymethod.is_sign_positive' class='fnname'>is_sign_positive</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></h3><div class='docblock'><p>Returns <code>true</code> if <code>self</code> is positive, including <code>+0.0</code>,
<code>Float::infinity()</code>, and since Rust 1.20 also <code>Float::nan()</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">neg_nan</span>: <span class="ident">f64</span> <span class="op">=</span> <span class="op">-</span><span class="ident">f64</span>::<span class="ident">NAN</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">7.0</span>;
<span class="kw">let</span> <span class="ident">g</span> <span class="op">=</span> <span class="op">-</span><span class="number">7.0</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">f</span>.<span class="ident">is_sign_positive</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">g</span>.<span class="ident">is_sign_positive</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">neg_nan</span>.<span class="ident">is_sign_positive</span>());</pre></div>
</div><h3 id='tymethod.is_sign_negative' class='method'><code id='is_sign_negative.v'>fn <a href='#tymethod.is_sign_negative' class='fnname'>is_sign_negative</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></h3><div class='docblock'><p>Returns <code>true</code> if <code>self</code> is negative, including <code>-0.0</code>,
<code>Float::neg_infinity()</code>, and since Rust 1.20 also <code>-Float::nan()</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">nan</span>: <span class="ident">f64</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">NAN</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">7.0</span>;
<span class="kw">let</span> <span class="ident">g</span> <span class="op">=</span> <span class="op">-</span><span class="number">7.0</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">f</span>.<span class="ident">is_sign_negative</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">g</span>.<span class="ident">is_sign_negative</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">nan</span>.<span class="ident">is_sign_negative</span>());</pre></div>
</div><h3 id='tymethod.mul_add' class='method'><code id='mul_add.v'>fn <a href='#tymethod.mul_add' class='fnname'>mul_add</a>(self, a: Self, b: Self) -&gt; Self</code></h3><div class='docblock'><p>Fused multiply-add. Computes <code>(self * a) + b</code> with only one rounding
error, yielding a more accurate result than an unfused multiply-add.</p>
<p>Using <code>mul_add</code> can be more performant than an unfused multiply-add if
the target architecture has a dedicated <code>fma</code> CPU instruction.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">m</span> <span class="op">=</span> <span class="number">10.0</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">4.0</span>;
<span class="kw">let</span> <span class="ident">b</span> <span class="op">=</span> <span class="number">60.0</span>;
<span class="comment">// 100.0</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">m</span>.<span class="ident">mul_add</span>(<span class="ident">x</span>, <span class="ident">b</span>) <span class="op">-</span> (<span class="ident">m</span><span class="kw-2">*</span><span class="ident">x</span> <span class="op">+</span> <span class="ident">b</span>)).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.recip' class='method'><code id='recip.v'>fn <a href='#tymethod.recip' class='fnname'>recip</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Take the reciprocal (inverse) of a number, <code>1/x</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">2.0</span>;
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">recip</span>() <span class="op">-</span> (<span class="number">1.0</span><span class="op">/</span><span class="ident">x</span>)).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.powi' class='method'><code id='powi.v'>fn <a href='#tymethod.powi' class='fnname'>powi</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>) -&gt; Self</code></h3><div class='docblock'><p>Raise a number to an integer power.</p>
<p>Using this function is generally faster than using <code>powf</code></p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">2.0</span>;
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">powi</span>(<span class="number">2</span>) <span class="op">-</span> <span class="ident">x</span><span class="kw-2">*</span><span class="ident">x</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.powf' class='method'><code id='powf.v'>fn <a href='#tymethod.powf' class='fnname'>powf</a>(self, n: Self) -&gt; Self</code></h3><div class='docblock'><p>Raise a number to a floating point power.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">2.0</span>;
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">powf</span>(<span class="number">2.0</span>) <span class="op">-</span> <span class="ident">x</span><span class="kw-2">*</span><span class="ident">x</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.sqrt' class='method'><code id='sqrt.v'>fn <a href='#tymethod.sqrt' class='fnname'>sqrt</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Take the square root of a number.</p>
<p>Returns NaN if <code>self</code> is a negative number.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">positive</span> <span class="op">=</span> <span class="number">4.0</span>;
<span class="kw">let</span> <span class="ident">negative</span> <span class="op">=</span> <span class="op">-</span><span class="number">4.0</span>;
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">positive</span>.<span class="ident">sqrt</span>() <span class="op">-</span> <span class="number">2.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">negative</span>.<span class="ident">sqrt</span>().<span class="ident">is_nan</span>());</pre></div>
</div><h3 id='tymethod.exp' class='method'><code id='exp.v'>fn <a href='#tymethod.exp' class='fnname'>exp</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns <code>e^(self)</code>, (the exponential function).</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">one</span> <span class="op">=</span> <span class="number">1.0</span>;
<span class="comment">// e^1</span>
<span class="kw">let</span> <span class="ident">e</span> <span class="op">=</span> <span class="ident">one</span>.<span class="ident">exp</span>();
<span class="comment">// ln(e) - 1 == 0</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">e</span>.<span class="ident">ln</span>() <span class="op">-</span> <span class="number">1.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.exp2' class='method'><code id='exp2.v'>fn <a href='#tymethod.exp2' class='fnname'>exp2</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns <code>2^(self)</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">2.0</span>;
<span class="comment">// 2^2 - 4 == 0</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">f</span>.<span class="ident">exp2</span>() <span class="op">-</span> <span class="number">4.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.ln' class='method'><code id='ln.v'>fn <a href='#tymethod.ln' class='fnname'>ln</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns the natural logarithm of the number.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">one</span> <span class="op">=</span> <span class="number">1.0</span>;
<span class="comment">// e^1</span>
<span class="kw">let</span> <span class="ident">e</span> <span class="op">=</span> <span class="ident">one</span>.<span class="ident">exp</span>();
<span class="comment">// ln(e) - 1 == 0</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">e</span>.<span class="ident">ln</span>() <span class="op">-</span> <span class="number">1.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.log' class='method'><code id='log.v'>fn <a href='#tymethod.log' class='fnname'>log</a>(self, base: Self) -&gt; Self</code></h3><div class='docblock'><p>Returns the logarithm of the number with respect to an arbitrary base.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">ten</span> <span class="op">=</span> <span class="number">10.0</span>;
<span class="kw">let</span> <span class="ident">two</span> <span class="op">=</span> <span class="number">2.0</span>;
<span class="comment">// log10(10) - 1 == 0</span>
<span class="kw">let</span> <span class="ident">abs_difference_10</span> <span class="op">=</span> (<span class="ident">ten</span>.<span class="ident">log</span>(<span class="number">10.0</span>) <span class="op">-</span> <span class="number">1.0</span>).<span class="ident">abs</span>();
<span class="comment">// log2(2) - 1 == 0</span>
<span class="kw">let</span> <span class="ident">abs_difference_2</span> <span class="op">=</span> (<span class="ident">two</span>.<span class="ident">log</span>(<span class="number">2.0</span>) <span class="op">-</span> <span class="number">1.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_10</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_2</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.log2' class='method'><code id='log2.v'>fn <a href='#tymethod.log2' class='fnname'>log2</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns the base 2 logarithm of the number.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">two</span> <span class="op">=</span> <span class="number">2.0</span>;
<span class="comment">// log2(2) - 1 == 0</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">two</span>.<span class="ident">log2</span>() <span class="op">-</span> <span class="number">1.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.log10' class='method'><code id='log10.v'>fn <a href='#tymethod.log10' class='fnname'>log10</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns the base 10 logarithm of the number.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">ten</span> <span class="op">=</span> <span class="number">10.0</span>;
<span class="comment">// log10(10) - 1 == 0</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">ten</span>.<span class="ident">log10</span>() <span class="op">-</span> <span class="number">1.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.max' class='method'><code id='max.v'>fn <a href='#tymethod.max' class='fnname'>max</a>(self, other: Self) -&gt; Self</code></h3><div class='docblock'><p>Returns the maximum of the two numbers.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">1.0</span>;
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="number">2.0</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">x</span>.<span class="ident">max</span>(<span class="ident">y</span>), <span class="ident">y</span>);</pre></div>
</div><h3 id='tymethod.min' class='method'><code id='min.v'>fn <a href='#tymethod.min' class='fnname'>min</a>(self, other: Self) -&gt; Self</code></h3><div class='docblock'><p>Returns the minimum of the two numbers.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">1.0</span>;
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="number">2.0</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">x</span>.<span class="ident">min</span>(<span class="ident">y</span>), <span class="ident">x</span>);</pre></div>
</div><h3 id='tymethod.abs_sub' class='method'><code id='abs_sub.v'>fn <a href='#tymethod.abs_sub' class='fnname'>abs_sub</a>(self, other: Self) -&gt; Self</code></h3><div class='docblock'><p>The positive difference of two numbers.</p>
<ul>
<li>If <code>self &lt;= other</code>: <code>0:0</code></li>
<li>Else: <code>self - other</code></li>
</ul>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">3.0</span>;
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="op">-</span><span class="number">3.0</span>;
<span class="kw">let</span> <span class="ident">abs_difference_x</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">abs_sub</span>(<span class="number">1.0</span>) <span class="op">-</span> <span class="number">2.0</span>).<span class="ident">abs</span>();
<span class="kw">let</span> <span class="ident">abs_difference_y</span> <span class="op">=</span> (<span class="ident">y</span>.<span class="ident">abs_sub</span>(<span class="number">1.0</span>) <span class="op">-</span> <span class="number">0.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_x</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_y</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.cbrt' class='method'><code id='cbrt.v'>fn <a href='#tymethod.cbrt' class='fnname'>cbrt</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Take the cubic root of a number.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">8.0</span>;
<span class="comment">// x^(1/3) - 2 == 0</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">cbrt</span>() <span class="op">-</span> <span class="number">2.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.hypot' class='method'><code id='hypot.v'>fn <a href='#tymethod.hypot' class='fnname'>hypot</a>(self, other: Self) -&gt; Self</code></h3><div class='docblock'><p>Calculate the length of the hypotenuse of a right-angle triangle given
legs of length <code>x</code> and <code>y</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">2.0</span>;
<span class="kw">let</span> <span class="ident">y</span> <span class="op">=</span> <span class="number">3.0</span>;
<span class="comment">// sqrt(x^2 + y^2)</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">hypot</span>(<span class="ident">y</span>) <span class="op">-</span> (<span class="ident">x</span>.<span class="ident">powi</span>(<span class="number">2</span>) <span class="op">+</span> <span class="ident">y</span>.<span class="ident">powi</span>(<span class="number">2</span>)).<span class="ident">sqrt</span>()).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.sin' class='method'><code id='sin.v'>fn <a href='#tymethod.sin' class='fnname'>sin</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Computes the sine of a number (in radians).</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">PI</span><span class="op">/</span><span class="number">2.0</span>;
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">sin</span>() <span class="op">-</span> <span class="number">1.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.cos' class='method'><code id='cos.v'>fn <a href='#tymethod.cos' class='fnname'>cos</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Computes the cosine of a number (in radians).</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">2.0</span><span class="kw-2">*</span><span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">PI</span>;
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">cos</span>() <span class="op">-</span> <span class="number">1.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.tan' class='method'><code id='tan.v'>fn <a href='#tymethod.tan' class='fnname'>tan</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Computes the tangent of a number (in radians).</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">PI</span><span class="op">/</span><span class="number">4.0</span>;
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">tan</span>() <span class="op">-</span> <span class="number">1.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-14</span>);</pre></div>
</div><h3 id='tymethod.asin' class='method'><code id='asin.v'>fn <a href='#tymethod.asin' class='fnname'>asin</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Computes the arcsine of a number. Return value is in radians in
the range [-pi/2, pi/2] or NaN if the number is outside the range
[-1, 1].</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">PI</span> <span class="op">/</span> <span class="number">2.0</span>;
<span class="comment">// asin(sin(pi/2))</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">f</span>.<span class="ident">sin</span>().<span class="ident">asin</span>() <span class="op">-</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">PI</span> <span class="op">/</span> <span class="number">2.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.acos' class='method'><code id='acos.v'>fn <a href='#tymethod.acos' class='fnname'>acos</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Computes the arccosine of a number. Return value is in radians in
the range [0, pi] or NaN if the number is outside the range
[-1, 1].</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">PI</span> <span class="op">/</span> <span class="number">4.0</span>;
<span class="comment">// acos(cos(pi/4))</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">f</span>.<span class="ident">cos</span>().<span class="ident">acos</span>() <span class="op">-</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">PI</span> <span class="op">/</span> <span class="number">4.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.atan' class='method'><code id='atan.v'>fn <a href='#tymethod.atan' class='fnname'>atan</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Computes the arctangent of a number. Return value is in radians in the
range [-pi/2, pi/2];</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="number">1.0</span>;
<span class="comment">// atan(tan(1))</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">f</span>.<span class="ident">tan</span>().<span class="ident">atan</span>() <span class="op">-</span> <span class="number">1.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.atan2' class='method'><code id='atan2.v'>fn <a href='#tymethod.atan2' class='fnname'>atan2</a>(self, other: Self) -&gt; Self</code></h3><div class='docblock'><p>Computes the four quadrant arctangent of <code>self</code> (<code>y</code>) and <code>other</code> (<code>x</code>).</p>
<ul>
<li><code>x = 0</code>, <code>y = 0</code>: <code>0</code></li>
<li><code>x &gt;= 0</code>: <code>arctan(y/x)</code> -&gt; <code>[-pi/2, pi/2]</code></li>
<li><code>y &gt;= 0</code>: <code>arctan(y/x) + pi</code> -&gt; <code>(pi/2, pi]</code></li>
<li><code>y &lt; 0</code>: <code>arctan(y/x) - pi</code> -&gt; <code>(-pi, -pi/2)</code></li>
</ul>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">pi</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">PI</span>;
<span class="comment">// All angles from horizontal right (+x)</span>
<span class="comment">// 45 deg counter-clockwise</span>
<span class="kw">let</span> <span class="ident">x1</span> <span class="op">=</span> <span class="number">3.0</span>;
<span class="kw">let</span> <span class="ident">y1</span> <span class="op">=</span> <span class="op">-</span><span class="number">3.0</span>;
<span class="comment">// 135 deg clockwise</span>
<span class="kw">let</span> <span class="ident">x2</span> <span class="op">=</span> <span class="op">-</span><span class="number">3.0</span>;
<span class="kw">let</span> <span class="ident">y2</span> <span class="op">=</span> <span class="number">3.0</span>;
<span class="kw">let</span> <span class="ident">abs_difference_1</span> <span class="op">=</span> (<span class="ident">y1</span>.<span class="ident">atan2</span>(<span class="ident">x1</span>) <span class="op">-</span> (<span class="op">-</span><span class="ident">pi</span><span class="op">/</span><span class="number">4.0</span>)).<span class="ident">abs</span>();
<span class="kw">let</span> <span class="ident">abs_difference_2</span> <span class="op">=</span> (<span class="ident">y2</span>.<span class="ident">atan2</span>(<span class="ident">x2</span>) <span class="op">-</span> <span class="number">3.0</span><span class="kw-2">*</span><span class="ident">pi</span><span class="op">/</span><span class="number">4.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_1</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_2</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.sin_cos' class='method'><code id='sin_cos.v'>fn <a href='#tymethod.sin_cos' class='fnname'>sin_cos</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>Self, Self<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code></h3><div class='docblock'><p>Simultaneously computes the sine and cosine of the number, <code>x</code>. Returns
<code>(sin(x), cos(x))</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">PI</span><span class="op">/</span><span class="number">4.0</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">sin_cos</span>();
<span class="kw">let</span> <span class="ident">abs_difference_0</span> <span class="op">=</span> (<span class="ident">f</span>.<span class="number">0</span> <span class="op">-</span> <span class="ident">x</span>.<span class="ident">sin</span>()).<span class="ident">abs</span>();
<span class="kw">let</span> <span class="ident">abs_difference_1</span> <span class="op">=</span> (<span class="ident">f</span>.<span class="number">1</span> <span class="op">-</span> <span class="ident">x</span>.<span class="ident">cos</span>()).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_0</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference_0</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.exp_m1' class='method'><code id='exp_m1.v'>fn <a href='#tymethod.exp_m1' class='fnname'>exp_m1</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns <code>e^(self) - 1</code> in a way that is accurate even if the
number is close to zero.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">7.0</span>;
<span class="comment">// e^(ln(7)) - 1</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">ln</span>().<span class="ident">exp_m1</span>() <span class="op">-</span> <span class="number">6.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.ln_1p' class='method'><code id='ln_1p.v'>fn <a href='#tymethod.ln_1p' class='fnname'>ln_1p</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Returns <code>ln(1+n)</code> (natural logarithm) more accurately than if
the operations were performed separately.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">E</span> <span class="op">-</span> <span class="number">1.0</span>;
<span class="comment">// ln(1 + (e - 1)) == ln(e) == 1</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">x</span>.<span class="ident">ln_1p</span>() <span class="op">-</span> <span class="number">1.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.sinh' class='method'><code id='sinh.v'>fn <a href='#tymethod.sinh' class='fnname'>sinh</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Hyperbolic sine function.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">e</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">E</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">1.0</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">sinh</span>();
<span class="comment">// Solving sinh() at 1 gives `(e^2-1)/(2e)`</span>
<span class="kw">let</span> <span class="ident">g</span> <span class="op">=</span> (<span class="ident">e</span><span class="kw-2">*</span><span class="ident">e</span> <span class="op">-</span> <span class="number">1.0</span>)<span class="op">/</span>(<span class="number">2.0</span><span class="kw-2">*</span><span class="ident">e</span>);
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">f</span> <span class="op">-</span> <span class="ident">g</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='tymethod.cosh' class='method'><code id='cosh.v'>fn <a href='#tymethod.cosh' class='fnname'>cosh</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Hyperbolic cosine function.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">e</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">E</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">1.0</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">cosh</span>();
<span class="comment">// Solving cosh() at 1 gives this result</span>
<span class="kw">let</span> <span class="ident">g</span> <span class="op">=</span> (<span class="ident">e</span><span class="kw-2">*</span><span class="ident">e</span> <span class="op">+</span> <span class="number">1.0</span>)<span class="op">/</span>(<span class="number">2.0</span><span class="kw-2">*</span><span class="ident">e</span>);
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">f</span> <span class="op">-</span> <span class="ident">g</span>).<span class="ident">abs</span>();
<span class="comment">// Same result</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1.0e-10</span>);</pre></div>
</div><h3 id='tymethod.tanh' class='method'><code id='tanh.v'>fn <a href='#tymethod.tanh' class='fnname'>tanh</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Hyperbolic tangent function.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">e</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">E</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">1.0</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">tanh</span>();
<span class="comment">// Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`</span>
<span class="kw">let</span> <span class="ident">g</span> <span class="op">=</span> (<span class="number">1.0</span> <span class="op">-</span> <span class="ident">e</span>.<span class="ident">powi</span>(<span class="op">-</span><span class="number">2</span>))<span class="op">/</span>(<span class="number">1.0</span> <span class="op">+</span> <span class="ident">e</span>.<span class="ident">powi</span>(<span class="op">-</span><span class="number">2</span>));
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">f</span> <span class="op">-</span> <span class="ident">g</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1.0e-10</span>);</pre></div>
</div><h3 id='tymethod.asinh' class='method'><code id='asinh.v'>fn <a href='#tymethod.asinh' class='fnname'>asinh</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Inverse hyperbolic sine function.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">1.0</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">sinh</span>().<span class="ident">asinh</span>();
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">f</span> <span class="op">-</span> <span class="ident">x</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1.0e-10</span>);</pre></div>
</div><h3 id='tymethod.acosh' class='method'><code id='acosh.v'>fn <a href='#tymethod.acosh' class='fnname'>acosh</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Inverse hyperbolic cosine function.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">1.0</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">cosh</span>().<span class="ident">acosh</span>();
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">f</span> <span class="op">-</span> <span class="ident">x</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1.0e-10</span>);</pre></div>
</div><h3 id='tymethod.atanh' class='method'><code id='atanh.v'>fn <a href='#tymethod.atanh' class='fnname'>atanh</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Inverse hyperbolic tangent function.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">e</span> <span class="op">=</span> <span class="ident">f64</span>::<span class="ident">consts</span>::<span class="ident">E</span>;
<span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="ident">e</span>.<span class="ident">tanh</span>().<span class="ident">atanh</span>();
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">f</span> <span class="op">-</span> <span class="ident">e</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1.0e-10</span>);</pre></div>
</div><h3 id='tymethod.integer_decode' class='method'><code id='integer_decode.v'>fn <a href='#tymethod.integer_decode' class='fnname'>integer_decode</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i16.html">i16</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i8.html">i8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code></h3><div class='docblock'><p>Returns the mantissa, base 2 exponent, and sign as integers, respectively.
The original number can be recovered by <code>sign * mantissa * 2 ^ exponent</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">let</span> <span class="ident">num</span> <span class="op">=</span> <span class="number">2.0f32</span>;
<span class="comment">// (8388608, -22, 1)</span>
<span class="kw">let</span> (<span class="ident">mantissa</span>, <span class="ident">exponent</span>, <span class="ident">sign</span>) <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">integer_decode</span>(<span class="ident">num</span>);
<span class="kw">let</span> <span class="ident">sign_f</span> <span class="op">=</span> <span class="ident">sign</span> <span class="kw">as</span> <span class="ident">f32</span>;
<span class="kw">let</span> <span class="ident">mantissa_f</span> <span class="op">=</span> <span class="ident">mantissa</span> <span class="kw">as</span> <span class="ident">f32</span>;
<span class="kw">let</span> <span class="ident">exponent_f</span> <span class="op">=</span> <span class="ident">num</span>.<span class="ident">powf</span>(<span class="ident">exponent</span> <span class="kw">as</span> <span class="ident">f32</span>);
<span class="comment">// 1 * 8388608 * 2^(-22) == 2</span>
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">sign_f</span> <span class="op">*</span> <span class="ident">mantissa_f</span> <span class="op">*</span> <span class="ident">exponent_f</span> <span class="op">-</span> <span class="ident">num</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div></div><span class='loading-content'>Loading content...</span>
<h2 id='provided-methods' class='small-section-header'>Provided methods<a href='#provided-methods' class='anchor'></a></h2><div class='methods'><h3 id='method.epsilon' class='method'><code id='epsilon.v'>fn <a href='#method.epsilon' class='fnname'>epsilon</a>() -&gt; Self</code></h3><div class='docblock'><p>Returns epsilon, a small positive value.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">Float</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>;
<span class="kw">let</span> <span class="ident">x</span>: <span class="ident">f64</span> <span class="op">=</span> <span class="ident">Float</span>::<span class="ident">epsilon</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">x</span>, <span class="ident">f64</span>::<span class="ident">EPSILON</span>);</pre></div>
<h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
<p>The default implementation will panic if <code>f32::EPSILON</code> cannot
be cast to <code>Self</code>.</p>
</div><h3 id='method.to_degrees' class='method'><code id='to_degrees.v'>fn <a href='#method.to_degrees' class='fnname'>to_degrees</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Converts radians to degrees.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>::<span class="ident">consts</span>;
<span class="kw">let</span> <span class="ident">angle</span> <span class="op">=</span> <span class="ident">consts</span>::<span class="ident">PI</span>;
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">angle</span>.<span class="ident">to_degrees</span>() <span class="op">-</span> <span class="number">180.0</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div><h3 id='method.to_radians' class='method'><code id='to_radians.v'>fn <a href='#method.to_radians' class='fnname'>to_radians</a>(self) -&gt; Self</code></h3><div class='docblock'><p>Converts degrees to radians.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">f64</span>::<span class="ident">consts</span>;
<span class="kw">let</span> <span class="ident">angle</span> <span class="op">=</span> <span class="number">180.0_f64</span>;
<span class="kw">let</span> <span class="ident">abs_difference</span> <span class="op">=</span> (<span class="ident">angle</span>.<span class="ident">to_radians</span>() <span class="op">-</span> <span class="ident">consts</span>::<span class="ident">PI</span>).<span class="ident">abs</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">abs_difference</span> <span class="op">&lt;</span> <span class="number">1e-10</span>);</pre></div>
</div></div><span class='loading-content'>Loading content...</span>
<h2 id='foreign-impls' class='small-section-header'>Implementations on Foreign Types<a href='#foreign-impls' class='anchor'></a></h2><h3 id='impl-Float-for-f32' class='impl'><code class='in-band'>impl <a class="trait" href="../../num_traits/float/trait.Float.html" title="trait num_traits::float::Float">Float</a> for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a></code><a href='#impl-Float-for-f32' class='anchor'></a><a class='srclink' href='../../src/num_traits/float.rs.html#1807-1879' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.nan' class="method hidden"><code id='nan.v-1'>fn <a href='#method.nan' class='fnname'>nan</a>() -&gt; Self</code><a class='srclink' href='../../src/num_traits/macros.rs.html#33-35' title='goto source code'>[src]</a></h4><h4 id='method.infinity' class="method hidden"><code id='infinity.v-1'>fn <a href='#method.infinity' class='fnname'>infinity</a>() -&gt; Self</code><a class='srclink' href='../../src/num_traits/macros.rs.html#33-35' title='goto source code'>[src]</a></h4><h4 id='method.neg_infinity' class="method hidden"><code id='neg_infinity.v-1'>fn <a href='#method.neg_infinity' class='fnname'>neg_infinity</a>() -&gt; Self</code><a class='srclink' href='../../src/num_traits/macros.rs.html#33-35' title='goto source code'>[src]</a></h4><h4 id='method.neg_zero' class="method hidden"><code id='neg_zero.v-1'>fn <a href='#method.neg_zero' class='fnname'>neg_zero</a>() -&gt; Self</code><a class='srclink' href='../../src/num_traits/macros.rs.html#33-35' title='goto source code'>[src]</a></h4><h4 id='method.min_value' class="method hidden"><code id='min_value.v-1'>fn <a href='#method.min_value' class='fnname'>min_value</a>() -&gt; Self</code><a class='srclink' href='../../src/num_traits/macros.rs.html#33-35' title='goto source code'>[src]</a></h4><h4 id='method.min_positive_value' class="method hidden"><code id='min_positive_value.v-1'>fn <a href='#method.min_positive_value' class='fnname'>min_positive_value</a>() -&gt; Self</code><a class='srclink' href='../../src/num_traits/macros.rs.html#33-35' title='goto source code'>[src]</a></h4><h4 id='method.epsilon-1' class="method hidden"><code id='epsilon.v-1'>fn <a href='#method.epsilon' class='fnname'>epsilon</a>() -&gt; Self</code><a class='srclink' href='../../src/num_traits/macros.rs.html#33-35' title='goto source code'>[src]</a></h4><h4 id='method.max_value' class="method hidden"><code id='max_value.v-1'>fn <a href='#method.max_value' class='fnname'>max_value</a>() -&gt; Self</code><a class='srclink' href='../../src/num_traits/macros.rs.html#33-35' title='goto source code'>[src]</a></h4><h4 id='method.abs_sub' class="method hidden"><code id='abs_sub.v-1'>fn <a href='#method.abs_sub' class='fnname'>abs_sub</a>(self, other: Self) -&gt; Self</code><a class='srclink' href='../../src/num_traits/float.rs.html#1821-1823' title='goto source code'>[src]</a></h4><h4 id='method.integer_decode' class="method hidden"><code id='integer_decode.v-1'>fn <a href='#method.integer_decode' class='fnname'>integer_decode</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i16.html">i16</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i8.html">i8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code><a class='srclink' href='../../src/num_traits/float.rs.html#1826-1828' title='goto source code'>[src]</a></h4><h4 id='method.is_nan' class="method hidden"><code id='is_nan.v-1'>fn <a href='#method.is_nan' class='fnname'>is_nan</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class='srclink' href='../../src/num_traits/macros.rs.html#9-11' title='goto source code'>[src]</a></h4><h4 id='method.is_infinite' class="method hidd
<h2 id='implementors' class='small-section-header'>Implementors<a href='#implementors' class='anchor'></a></h2><div class='item-list' id='implementors-list'></div><span class='loading-content'>Loading content...</span><script type="text/javascript">window.inlined_types=new Set([]);</script><script type="text/javascript" async
src="../../implementors/num_traits/float/trait.Float.js">
</script></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd></kbd></dt><dd>Move up in search results</dd><dt><kbd></kbd></dt><dd>Move down in search results</dd><dt><kbd></kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "num_traits";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>