mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-28 12:51:55 +01:00
480 lines
64 KiB
HTML
480 lines
64 KiB
HTML
<!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="Generic trait for floating point numbers that works with `no_std`."><title>FloatCore in num_traits::float - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="num_traits" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../num_traits/index.html">num_traits</a><span class="version">0.2.17</span></h2></div><h2 class="location"><a href="#">FloatCore</a></h2><div class="sidebar-elems"><section><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.classify">classify</a></li><li><a href="#tymethod.epsilon">epsilon</a></li><li><a href="#tymethod.infinity">infinity</a></li><li><a href="#tymethod.integer_decode">integer_decode</a></li><li><a href="#tymethod.max_value">max_value</a></li><li><a href="#tymethod.min_positive_value">min_positive_value</a></li><li><a href="#tymethod.min_value">min_value</a></li><li><a href="#tymethod.nan">nan</a></li><li><a href="#tymethod.neg_infinity">neg_infinity</a></li><li><a href="#tymethod.neg_zero">neg_zero</a></li><li><a href="#tymethod.to_degrees">to_degrees</a></li><li><a href="#tymethod.to_radians">to_radians</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.abs">abs</a></li><li><a href="#method.ceil">ceil</a></li><li><a href="#method.floor">floor</a></li><li><a href="#method.fract">fract</a></li><li><a href="#method.is_finite">is_finite</a></li><li><a href="#method.is_infinite">is_infinite</a></li><li><a href="#method.is_nan">is_nan</a></li><li><a href="#method.is_normal">is_normal</a></li><li><a href="#method.is_sign_negative">is_sign_negative</a></li><li><a href="#method.is_sign_positive">is_sign_positive</a></li><li><a href="#method.is_subnormal">is_subnormal</a></li><li><a href="#method.max">max</a></li><li><a href="#method.min">min</a></li><li><a href="#method.powi">powi</a></li><li><a href="#method.recip">recip</a></li><li><a href="#method.round">round</a></li><li><a href="#method.signum">signum</a></li><li><a href="#method.trunc">trunc</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-FloatCore-for-f32">f32</a></li><li><a href="#impl-FloatCore-for-f64">f64</a></li></ul><h3><a href="#object-safety">Object Safety</a></h3><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In num_traits::float</a></h2></div></nav><div class="sidebar-resizer"></div>
|
||
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../../num_traits/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Trait <a href="../index.html">num_traits</a>::<wbr><a href="index.html">float</a>::<wbr><a class="trait" href="#">FloatCore</a><button id="copy-path" title="Copy item path to clipboard"><img src="../../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../../src/num_traits/float.rs.html#12-768">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub trait FloatCore: <a class="trait" href="../trait.Num.html" title="trait num_traits::Num">Num</a> + <a class="trait" href="../cast/trait.NumCast.html" title="trait num_traits::cast::NumCast">NumCast</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/arith/trait.Neg.html" title="trait core::ops::arith::Neg">Neg</a><Output = Self> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a> {
|
||
<details class="toggle type-contents-toggle"><summary class="hideme"><span>Show 30 methods</span></summary> // Required methods
|
||
fn <a href="#tymethod.infinity" class="fn">infinity</a>() -> Self;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.neg_infinity" class="fn">neg_infinity</a>() -> Self;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.nan" class="fn">nan</a>() -> Self;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.neg_zero" class="fn">neg_zero</a>() -> Self;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.min_value" class="fn">min_value</a>() -> Self;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.min_positive_value" class="fn">min_positive_value</a>() -> Self;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.epsilon" class="fn">epsilon</a>() -> Self;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.max_value" class="fn">max_value</a>() -> Self;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.classify" class="fn">classify</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/num/enum.FpCategory.html" title="enum core::num::FpCategory">FpCategory</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.to_degrees" class="fn">to_degrees</a>(self) -> Self;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.to_radians" class="fn">to_radians</a>(self) -> Self;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.integer_decode" class="fn">integer_decode</a>(self) -> (<a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.u64.html">u64</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.i16.html">i16</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.i8.html">i8</a>);
|
||
|
||
// Provided methods
|
||
fn <a href="#method.is_nan" class="fn">is_nan</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a> { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.is_infinite" class="fn">is_infinite</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a> { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.is_finite" class="fn">is_finite</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a> { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.is_normal" class="fn">is_normal</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a> { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.is_subnormal" class="fn">is_subnormal</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a> { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.floor" class="fn">floor</a>(self) -> Self { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.ceil" class="fn">ceil</a>(self) -> Self { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.round" class="fn">round</a>(self) -> Self { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.trunc" class="fn">trunc</a>(self) -> Self { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.fract" class="fn">fract</a>(self) -> Self { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.abs" class="fn">abs</a>(self) -> Self { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.signum" class="fn">signum</a>(self) -> Self { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.is_sign_positive" class="fn">is_sign_positive</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a> { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.is_sign_negative" class="fn">is_sign_negative</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a> { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.min" class="fn">min</a>(self, other: Self) -> Self { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.max" class="fn">max</a>(self, other: Self) -> Self { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.recip" class="fn">recip</a>(self) -> Self { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.powi" class="fn">powi</a>(self, exp: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.i32.html">i32</a>) -> Self { ... }
|
||
</details>}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Generic trait for floating point numbers that works with <code>no_std</code>.</p>
|
||
<p>This trait implements a subset of the <code>Float</code> trait.</p>
|
||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.infinity" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#28">source</a><h4 class="code-header">fn <a href="#tymethod.infinity" class="fn">infinity</a>() -> Self</h4></section></summary><div class="docblock"><p>Returns positive infinity.</p>
|
||
<h5 id="examples"><a href="#examples">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T) {
|
||
<span class="macro">assert!</span>(T::infinity() == x);
|
||
}
|
||
|
||
check(f32::INFINITY);
|
||
check(f64::INFINITY);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.neg_infinity" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#45">source</a><h4 class="code-header">fn <a href="#tymethod.neg_infinity" class="fn">neg_infinity</a>() -> Self</h4></section></summary><div class="docblock"><p>Returns negative infinity.</p>
|
||
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T) {
|
||
<span class="macro">assert!</span>(T::neg_infinity() == x);
|
||
}
|
||
|
||
check(f32::NEG_INFINITY);
|
||
check(f64::NEG_INFINITY);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.nan" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#62">source</a><h4 class="code-header">fn <a href="#tymethod.nan" class="fn">nan</a>() -> Self</h4></section></summary><div class="docblock"><p>Returns NaN.</p>
|
||
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>() {
|
||
<span class="kw">let </span>n = T::nan();
|
||
<span class="macro">assert!</span>(n != n);
|
||
}
|
||
|
||
check::<f32>();
|
||
check::<f64>();</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.neg_zero" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#81">source</a><h4 class="code-header">fn <a href="#tymethod.neg_zero" class="fn">neg_zero</a>() -> Self</h4></section></summary><div class="docblock"><p>Returns <code>-0.0</code>.</p>
|
||
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(n: T) {
|
||
<span class="kw">let </span>z = T::neg_zero();
|
||
<span class="macro">assert!</span>(z.is_zero());
|
||
<span class="macro">assert!</span>(T::one() / z == n);
|
||
}
|
||
|
||
check(f32::NEG_INFINITY);
|
||
check(f64::NEG_INFINITY);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.min_value" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#98">source</a><h4 class="code-header">fn <a href="#tymethod.min_value" class="fn">min_value</a>() -> Self</h4></section></summary><div class="docblock"><p>Returns the smallest finite value that this type can represent.</p>
|
||
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T) {
|
||
<span class="macro">assert!</span>(T::min_value() == x);
|
||
}
|
||
|
||
check(f32::MIN);
|
||
check(f64::MIN);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.min_positive_value" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#115">source</a><h4 class="code-header">fn <a href="#tymethod.min_positive_value" class="fn">min_positive_value</a>() -> Self</h4></section></summary><div class="docblock"><p>Returns the smallest positive, normalized value that this type can represent.</p>
|
||
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T) {
|
||
<span class="macro">assert!</span>(T::min_positive_value() == x);
|
||
}
|
||
|
||
check(f32::MIN_POSITIVE);
|
||
check(f64::MIN_POSITIVE);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.epsilon" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#132">source</a><h4 class="code-header">fn <a href="#tymethod.epsilon" class="fn">epsilon</a>() -> Self</h4></section></summary><div class="docblock"><p>Returns epsilon, a small positive value.</p>
|
||
<h5 id="examples-6"><a href="#examples-6">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T) {
|
||
<span class="macro">assert!</span>(T::epsilon() == x);
|
||
}
|
||
|
||
check(f32::EPSILON);
|
||
check(f64::EPSILON);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.max_value" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#149">source</a><h4 class="code-header">fn <a href="#tymethod.max_value" class="fn">max_value</a>() -> Self</h4></section></summary><div class="docblock"><p>Returns the largest finite value that this type can represent.</p>
|
||
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T) {
|
||
<span class="macro">assert!</span>(T::max_value() == x);
|
||
}
|
||
|
||
check(f32::MAX);
|
||
check(f64::MAX);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.classify" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#292">source</a><h4 class="code-header">fn <a href="#tymethod.classify" class="fn">classify</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/num/enum.FpCategory.html" title="enum core::num::FpCategory">FpCategory</a></h4></section></summary><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>
|
||
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
<span class="kw">use </span>std::num::FpCategory;
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, c: FpCategory) {
|
||
<span class="macro">assert!</span>(x.classify() == c);
|
||
}
|
||
|
||
check(f32::INFINITY, FpCategory::Infinite);
|
||
check(f32::MAX, FpCategory::Normal);
|
||
check(f64::NAN, FpCategory::Nan);
|
||
check(f64::MIN_POSITIVE, FpCategory::Normal);
|
||
check(f64::MIN_POSITIVE / <span class="number">2.0</span>, FpCategory::Subnormal);
|
||
check(<span class="number">0.0f64</span>, FpCategory::Zero);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.to_degrees" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#725">source</a><h4 class="code-header">fn <a href="#tymethod.to_degrees" class="fn">to_degrees</a>(self) -> Self</h4></section></summary><div class="docblock"><p>Converts to degrees, assuming the number is in radians.</p>
|
||
<h5 id="examples-9"><a href="#examples-9">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(rad: T, deg: T) {
|
||
<span class="macro">assert!</span>(rad.to_degrees() == deg);
|
||
}
|
||
|
||
check(<span class="number">0.0f32</span>, <span class="number">0.0</span>);
|
||
check(f32::consts::PI, <span class="number">180.0</span>);
|
||
check(f64::consts::FRAC_PI_4, <span class="number">45.0</span>);
|
||
check(f64::INFINITY, f64::INFINITY);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.to_radians" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#744">source</a><h4 class="code-header">fn <a href="#tymethod.to_radians" class="fn">to_radians</a>(self) -> Self</h4></section></summary><div class="docblock"><p>Converts to radians, assuming the number is in degrees.</p>
|
||
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(deg: T, rad: T) {
|
||
<span class="macro">assert!</span>(deg.to_radians() == rad);
|
||
}
|
||
|
||
check(<span class="number">0.0f32</span>, <span class="number">0.0</span>);
|
||
check(<span class="number">180.0</span>, f32::consts::PI);
|
||
check(<span class="number">45.0</span>, f64::consts::FRAC_PI_4);
|
||
check(f64::INFINITY, f64::INFINITY);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.integer_decode" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#767">source</a><h4 class="code-header">fn <a href="#tymethod.integer_decode" class="fn">integer_decode</a>(self) -> (<a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.u64.html">u64</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.i16.html">i16</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.i8.html">i8</a>)</h4></section></summary><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>
|
||
<h5 id="examples-11"><a href="#examples-11">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, m: u64, e: i16, s:i8) {
|
||
<span class="kw">let </span>(mantissa, exponent, sign) = x.integer_decode();
|
||
<span class="macro">assert_eq!</span>(mantissa, m);
|
||
<span class="macro">assert_eq!</span>(exponent, e);
|
||
<span class="macro">assert_eq!</span>(sign, s);
|
||
}
|
||
|
||
check(<span class="number">2.0f32</span>, <span class="number">1 </span><< <span class="number">23</span>, -<span class="number">22</span>, <span class="number">1</span>);
|
||
check(-<span class="number">2.0f32</span>, <span class="number">1 </span><< <span class="number">23</span>, -<span class="number">22</span>, -<span class="number">1</span>);
|
||
check(f32::INFINITY, <span class="number">1 </span><< <span class="number">23</span>, <span class="number">105</span>, <span class="number">1</span>);
|
||
check(f64::NEG_INFINITY, <span class="number">1 </span><< <span class="number">52</span>, <span class="number">972</span>, -<span class="number">1</span>);</code></pre></div>
|
||
</div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.is_nan" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#170-172">source</a><h4 class="code-header">fn <a href="#method.is_nan" class="fn">is_nan</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the number is NaN.</p>
|
||
<h5 id="examples-12"><a href="#examples-12">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, p: bool) {
|
||
<span class="macro">assert!</span>(x.is_nan() == p);
|
||
}
|
||
|
||
check(f32::NAN, <span class="bool-val">true</span>);
|
||
check(f32::INFINITY, <span class="bool-val">false</span>);
|
||
check(f64::NAN, <span class="bool-val">true</span>);
|
||
check(<span class="number">0.0f64</span>, <span class="bool-val">false</span>);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_infinite" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#194-196">source</a><h4 class="code-header">fn <a href="#method.is_infinite" class="fn">is_infinite</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the number is infinite.</p>
|
||
<h5 id="examples-13"><a href="#examples-13">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, p: bool) {
|
||
<span class="macro">assert!</span>(x.is_infinite() == p);
|
||
}
|
||
|
||
check(f32::INFINITY, <span class="bool-val">true</span>);
|
||
check(f32::NEG_INFINITY, <span class="bool-val">true</span>);
|
||
check(f32::NAN, <span class="bool-val">false</span>);
|
||
check(f64::INFINITY, <span class="bool-val">true</span>);
|
||
check(f64::NEG_INFINITY, <span class="bool-val">true</span>);
|
||
check(<span class="number">0.0f64</span>, <span class="bool-val">false</span>);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_finite" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#217-219">source</a><h4 class="code-header">fn <a href="#method.is_finite" class="fn">is_finite</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the number is neither infinite or NaN.</p>
|
||
<h5 id="examples-14"><a href="#examples-14">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, p: bool) {
|
||
<span class="macro">assert!</span>(x.is_finite() == p);
|
||
}
|
||
|
||
check(f32::INFINITY, <span class="bool-val">false</span>);
|
||
check(f32::MAX, <span class="bool-val">true</span>);
|
||
check(f64::NEG_INFINITY, <span class="bool-val">false</span>);
|
||
check(f64::MIN_POSITIVE, <span class="bool-val">true</span>);
|
||
check(f64::NAN, <span class="bool-val">false</span>);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_normal" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#240-242">source</a><h4 class="code-header">fn <a href="#method.is_normal" class="fn">is_normal</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the number is neither zero, infinite, subnormal or NaN.</p>
|
||
<h5 id="examples-15"><a href="#examples-15">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, p: bool) {
|
||
<span class="macro">assert!</span>(x.is_normal() == p);
|
||
}
|
||
|
||
check(f32::INFINITY, <span class="bool-val">false</span>);
|
||
check(f32::MAX, <span class="bool-val">true</span>);
|
||
check(f64::NEG_INFINITY, <span class="bool-val">false</span>);
|
||
check(f64::MIN_POSITIVE, <span class="bool-val">true</span>);
|
||
check(<span class="number">0.0f64</span>, <span class="bool-val">false</span>);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_subnormal" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#266-268">source</a><h4 class="code-header">fn <a href="#method.is_subnormal" class="fn">is_subnormal</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the number is <a href="https://en.wikipedia.org/wiki/Subnormal_number">subnormal</a>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::f64;
|
||
|
||
<span class="kw">let </span>min = f64::MIN_POSITIVE; <span class="comment">// 2.2250738585072014e-308_f64
|
||
</span><span class="kw">let </span>max = f64::MAX;
|
||
<span class="kw">let </span>lower_than_min = <span class="number">1.0e-308_f64</span>;
|
||
<span class="kw">let </span>zero = <span class="number">0.0_f64</span>;
|
||
|
||
<span class="macro">assert!</span>(!min.is_subnormal());
|
||
<span class="macro">assert!</span>(!max.is_subnormal());
|
||
|
||
<span class="macro">assert!</span>(!zero.is_subnormal());
|
||
<span class="macro">assert!</span>(!f64::NAN.is_subnormal());
|
||
<span class="macro">assert!</span>(!f64::INFINITY.is_subnormal());
|
||
<span class="comment">// Values between `0` and `min` are Subnormal.
|
||
</span><span class="macro">assert!</span>(lower_than_min.is_subnormal());</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.floor" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#317-326">source</a><h4 class="code-header">fn <a href="#method.floor" class="fn">floor</a>(self) -> Self</h4></section></summary><div class="docblock"><p>Returns the largest integer less than or equal to a number.</p>
|
||
<h5 id="examples-16"><a href="#examples-16">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, y: T) {
|
||
<span class="macro">assert!</span>(x.floor() == y);
|
||
}
|
||
|
||
check(f32::INFINITY, f32::INFINITY);
|
||
check(<span class="number">0.9f32</span>, <span class="number">0.0</span>);
|
||
check(<span class="number">1.0f32</span>, <span class="number">1.0</span>);
|
||
check(<span class="number">1.1f32</span>, <span class="number">1.0</span>);
|
||
check(-<span class="number">0.0f64</span>, <span class="number">0.0</span>);
|
||
check(-<span class="number">0.9f64</span>, -<span class="number">1.0</span>);
|
||
check(-<span class="number">1.0f64</span>, -<span class="number">1.0</span>);
|
||
check(-<span class="number">1.1f64</span>, -<span class="number">2.0</span>);
|
||
check(f64::MIN, f64::MIN);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.ceil" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#351-360">source</a><h4 class="code-header">fn <a href="#method.ceil" class="fn">ceil</a>(self) -> Self</h4></section></summary><div class="docblock"><p>Returns the smallest integer greater than or equal to a number.</p>
|
||
<h5 id="examples-17"><a href="#examples-17">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, y: T) {
|
||
<span class="macro">assert!</span>(x.ceil() == y);
|
||
}
|
||
|
||
check(f32::INFINITY, f32::INFINITY);
|
||
check(<span class="number">0.9f32</span>, <span class="number">1.0</span>);
|
||
check(<span class="number">1.0f32</span>, <span class="number">1.0</span>);
|
||
check(<span class="number">1.1f32</span>, <span class="number">2.0</span>);
|
||
check(-<span class="number">0.0f64</span>, <span class="number">0.0</span>);
|
||
check(-<span class="number">0.9f64</span>, -<span class="number">0.0</span>);
|
||
check(-<span class="number">1.0f64</span>, -<span class="number">1.0</span>);
|
||
check(-<span class="number">1.1f64</span>, -<span class="number">1.0</span>);
|
||
check(f64::MIN, f64::MIN);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.round" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#384-401">source</a><h4 class="code-header">fn <a href="#method.round" class="fn">round</a>(self) -> Self</h4></section></summary><div class="docblock"><p>Returns the nearest integer to a number. Round half-way cases away from <code>0.0</code>.</p>
|
||
<h5 id="examples-18"><a href="#examples-18">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, y: T) {
|
||
<span class="macro">assert!</span>(x.round() == y);
|
||
}
|
||
|
||
check(f32::INFINITY, f32::INFINITY);
|
||
check(<span class="number">0.4f32</span>, <span class="number">0.0</span>);
|
||
check(<span class="number">0.5f32</span>, <span class="number">1.0</span>);
|
||
check(<span class="number">0.6f32</span>, <span class="number">1.0</span>);
|
||
check(-<span class="number">0.4f64</span>, <span class="number">0.0</span>);
|
||
check(-<span class="number">0.5f64</span>, -<span class="number">1.0</span>);
|
||
check(-<span class="number">0.6f64</span>, -<span class="number">1.0</span>);
|
||
check(f64::MIN, f64::MIN);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.trunc" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#426-433">source</a><h4 class="code-header">fn <a href="#method.trunc" class="fn">trunc</a>(self) -> Self</h4></section></summary><div class="docblock"><p>Return the integer part of a number.</p>
|
||
<h5 id="examples-19"><a href="#examples-19">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, y: T) {
|
||
<span class="macro">assert!</span>(x.trunc() == y);
|
||
}
|
||
|
||
check(f32::INFINITY, f32::INFINITY);
|
||
check(<span class="number">0.9f32</span>, <span class="number">0.0</span>);
|
||
check(<span class="number">1.0f32</span>, <span class="number">1.0</span>);
|
||
check(<span class="number">1.1f32</span>, <span class="number">1.0</span>);
|
||
check(-<span class="number">0.0f64</span>, <span class="number">0.0</span>);
|
||
check(-<span class="number">0.9f64</span>, -<span class="number">0.0</span>);
|
||
check(-<span class="number">1.0f64</span>, -<span class="number">1.0</span>);
|
||
check(-<span class="number">1.1f64</span>, -<span class="number">1.0</span>);
|
||
check(f64::MIN, f64::MIN);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.fract" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#458-464">source</a><h4 class="code-header">fn <a href="#method.fract" class="fn">fract</a>(self) -> Self</h4></section></summary><div class="docblock"><p>Returns the fractional part of a number.</p>
|
||
<h5 id="examples-20"><a href="#examples-20">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, y: T) {
|
||
<span class="macro">assert!</span>(x.fract() == y);
|
||
}
|
||
|
||
check(f32::MAX, <span class="number">0.0</span>);
|
||
check(<span class="number">0.75f32</span>, <span class="number">0.75</span>);
|
||
check(<span class="number">1.0f32</span>, <span class="number">0.0</span>);
|
||
check(<span class="number">1.25f32</span>, <span class="number">0.25</span>);
|
||
check(-<span class="number">0.0f64</span>, <span class="number">0.0</span>);
|
||
check(-<span class="number">0.75f64</span>, -<span class="number">0.75</span>);
|
||
check(-<span class="number">1.0f64</span>, <span class="number">0.0</span>);
|
||
check(-<span class="number">1.25f64</span>, -<span class="number">0.25</span>);
|
||
check(f64::MIN, <span class="number">0.0</span>);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.abs" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#487-495">source</a><h4 class="code-header">fn <a href="#method.abs" class="fn">abs</a>(self) -> Self</h4></section></summary><div class="docblock"><p>Computes the absolute value of <code>self</code>. Returns <code>FloatCore::nan()</code> if the
|
||
number is <code>FloatCore::nan()</code>.</p>
|
||
<h5 id="examples-21"><a href="#examples-21">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, y: T) {
|
||
<span class="macro">assert!</span>(x.abs() == y);
|
||
}
|
||
|
||
check(f32::INFINITY, f32::INFINITY);
|
||
check(<span class="number">1.0f32</span>, <span class="number">1.0</span>);
|
||
check(<span class="number">0.0f64</span>, <span class="number">0.0</span>);
|
||
check(-<span class="number">0.0f64</span>, <span class="number">0.0</span>);
|
||
check(-<span class="number">1.0f64</span>, <span class="number">1.0</span>);
|
||
check(f64::MIN, f64::MAX);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.signum" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#521-529">source</a><h4 class="code-header">fn <a href="#method.signum" class="fn">signum</a>(self) -> Self</h4></section></summary><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>FloatCore::infinity()</code></li>
|
||
<li><code>-1.0</code> if the number is negative, <code>-0.0</code> or <code>FloatCore::neg_infinity()</code></li>
|
||
<li><code>FloatCore::nan()</code> if the number is <code>FloatCore::nan()</code></li>
|
||
</ul>
|
||
<h5 id="examples-22"><a href="#examples-22">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, y: T) {
|
||
<span class="macro">assert!</span>(x.signum() == y);
|
||
}
|
||
|
||
check(f32::INFINITY, <span class="number">1.0</span>);
|
||
check(<span class="number">3.0f32</span>, <span class="number">1.0</span>);
|
||
check(<span class="number">0.0f32</span>, <span class="number">1.0</span>);
|
||
check(-<span class="number">0.0f64</span>, -<span class="number">1.0</span>);
|
||
check(-<span class="number">3.0f64</span>, -<span class="number">1.0</span>);
|
||
check(f64::MIN, -<span class="number">1.0</span>);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_sign_positive" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#554-556">source</a><h4 class="code-header">fn <a href="#method.is_sign_positive" class="fn">is_sign_positive</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if <code>self</code> is positive, including <code>+0.0</code> and
|
||
<code>FloatCore::infinity()</code>, and <code>FloatCore::nan()</code>.</p>
|
||
<h5 id="examples-23"><a href="#examples-23">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, p: bool) {
|
||
<span class="macro">assert!</span>(x.is_sign_positive() == p);
|
||
}
|
||
|
||
check(f32::INFINITY, <span class="bool-val">true</span>);
|
||
check(f32::MAX, <span class="bool-val">true</span>);
|
||
check(<span class="number">0.0f32</span>, <span class="bool-val">true</span>);
|
||
check(-<span class="number">0.0f64</span>, <span class="bool-val">false</span>);
|
||
check(f64::NEG_INFINITY, <span class="bool-val">false</span>);
|
||
check(f64::MIN_POSITIVE, <span class="bool-val">true</span>);
|
||
check(f64::NAN, <span class="bool-val">true</span>);
|
||
check(-f64::NAN, <span class="bool-val">false</span>);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_sign_negative" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#581-584">source</a><h4 class="code-header">fn <a href="#method.is_sign_negative" class="fn">is_sign_negative</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if <code>self</code> is negative, including <code>-0.0</code> and
|
||
<code>FloatCore::neg_infinity()</code>, and <code>-FloatCore::nan()</code>.</p>
|
||
<h5 id="examples-24"><a href="#examples-24">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, p: bool) {
|
||
<span class="macro">assert!</span>(x.is_sign_negative() == p);
|
||
}
|
||
|
||
check(f32::INFINITY, <span class="bool-val">false</span>);
|
||
check(f32::MAX, <span class="bool-val">false</span>);
|
||
check(<span class="number">0.0f32</span>, <span class="bool-val">false</span>);
|
||
check(-<span class="number">0.0f64</span>, <span class="bool-val">true</span>);
|
||
check(f64::NEG_INFINITY, <span class="bool-val">true</span>);
|
||
check(f64::MIN_POSITIVE, <span class="bool-val">false</span>);
|
||
check(f64::NAN, <span class="bool-val">false</span>);
|
||
check(-f64::NAN, <span class="bool-val">true</span>);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.min" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#606-618">source</a><h4 class="code-header">fn <a href="#method.min" class="fn">min</a>(self, other: Self) -> Self</h4></section></summary><div class="docblock"><p>Returns the minimum of the two numbers.</p>
|
||
<p>If one of the arguments is NaN, then the other argument is returned.</p>
|
||
<h5 id="examples-25"><a href="#examples-25">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, y: T, min: T) {
|
||
<span class="macro">assert!</span>(x.min(y) == min);
|
||
}
|
||
|
||
check(<span class="number">1.0f32</span>, <span class="number">2.0</span>, <span class="number">1.0</span>);
|
||
check(f32::NAN, <span class="number">2.0</span>, <span class="number">2.0</span>);
|
||
check(<span class="number">1.0f64</span>, -<span class="number">2.0</span>, -<span class="number">2.0</span>);
|
||
check(<span class="number">1.0f64</span>, f64::NAN, <span class="number">1.0</span>);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.max" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#640-652">source</a><h4 class="code-header">fn <a href="#method.max" class="fn">max</a>(self, other: Self) -> Self</h4></section></summary><div class="docblock"><p>Returns the maximum of the two numbers.</p>
|
||
<p>If one of the arguments is NaN, then the other argument is returned.</p>
|
||
<h5 id="examples-26"><a href="#examples-26">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, y: T, max: T) {
|
||
<span class="macro">assert!</span>(x.max(y) == max);
|
||
}
|
||
|
||
check(<span class="number">1.0f32</span>, <span class="number">2.0</span>, <span class="number">2.0</span>);
|
||
check(<span class="number">1.0f32</span>, f32::NAN, <span class="number">1.0</span>);
|
||
check(-<span class="number">1.0f64</span>, <span class="number">2.0</span>, <span class="number">2.0</span>);
|
||
check(-<span class="number">1.0f64</span>, f64::NAN, -<span class="number">1.0</span>);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.recip" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#673-675">source</a><h4 class="code-header">fn <a href="#method.recip" class="fn">recip</a>(self) -> Self</h4></section></summary><div class="docblock"><p>Returns the reciprocal (multiplicative inverse) of the number.</p>
|
||
<h5 id="examples-27"><a href="#examples-27">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
<span class="kw">use </span>std::{f32, f64};
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, y: T) {
|
||
<span class="macro">assert!</span>(x.recip() == y);
|
||
<span class="macro">assert!</span>(y.recip() == x);
|
||
}
|
||
|
||
check(f32::INFINITY, <span class="number">0.0</span>);
|
||
check(<span class="number">2.0f32</span>, <span class="number">0.5</span>);
|
||
check(-<span class="number">0.25f64</span>, -<span class="number">4.0</span>);
|
||
check(-<span class="number">0.0f64</span>, f64::NEG_INFINITY);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.powi" class="method"><a class="src rightside" href="../../src/num_traits/float.rs.html#697-706">source</a><h4 class="code-header">fn <a href="#method.powi" class="fn">powi</a>(self, exp: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.i32.html">i32</a>) -> Self</h4></section></summary><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>
|
||
<h5 id="examples-28"><a href="#examples-28">Examples</a></h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::float::FloatCore;
|
||
|
||
<span class="kw">fn </span>check<T: FloatCore>(x: T, exp: i32, powi: T) {
|
||
<span class="macro">assert!</span>(x.powi(exp) == powi);
|
||
}
|
||
|
||
check(<span class="number">9.0f32</span>, <span class="number">2</span>, <span class="number">81.0</span>);
|
||
check(<span class="number">1.0f32</span>, -<span class="number">2</span>, <span class="number">1.0</span>);
|
||
check(<span class="number">10.0f64</span>, <span class="number">20</span>, <span class="number">1e20</span>);
|
||
check(<span class="number">4.0f64</span>, -<span class="number">2</span>, <span class="number">0.0625</span>);
|
||
check(-<span class="number">1.0f64</span>, std::i32::MIN, <span class="number">1.0</span>);</code></pre></div>
|
||
</div></details></div><h2 id="object-safety" class="section-header">Object Safety<a href="#object-safety" class="anchor">§</a></h2><div class="object-safety-info">This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.76.0/reference/items/traits.html#object-safety">object safe</a>.</div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-FloatCore-for-f32" class="impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#770-833">source</a><a href="#impl-FloatCore-for-f32" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.FloatCore.html" title="trait num_traits::float::FloatCore">FloatCore</a> for <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.f32.html">f32</a></h3></section></summary><div class="impl-items"><section id="method.infinity" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#771-780">source</a><a href="#method.infinity" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.infinity" class="fn">infinity</a>() -> Self</h4></section><section id="method.neg_infinity" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#771-780">source</a><a href="#method.neg_infinity" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.neg_infinity" class="fn">neg_infinity</a>() -> Self</h4></section><section id="method.nan" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#771-780">source</a><a href="#method.nan" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.nan" class="fn">nan</a>() -> Self</h4></section><section id="method.neg_zero" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#771-780">source</a><a href="#method.neg_zero" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.neg_zero" class="fn">neg_zero</a>() -> Self</h4></section><section id="method.min_value" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#771-780">source</a><a href="#method.min_value" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.min_value" class="fn">min_value</a>() -> Self</h4></section><section id="method.min_positive_value" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#771-780">source</a><a href="#method.min_positive_value" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.min_positive_value" class="fn">min_positive_value</a>() -> Self</h4></section><section id="method.epsilon" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#771-780">source</a><a href="#method.epsilon" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.epsilon" class="fn">epsilon</a>() -> Self</h4></section><section id="method.max_value" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#771-780">source</a><a href="#method.max_value" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.max_value" class="fn">max_value</a>() -> Self</h4></section><section id="method.integer_decode" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#783-785">source</a><a href="#method.integer_decode" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.integer_decode" class="fn">integer_decode</a>(self) -> (<a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.u64.html">u64</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.i16.html">i16</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.i8.html">i8</a>)</h4></section><section id="method.is_nan-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.is_nan-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_nan" class="fn">is_nan</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.is_infinite-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.is_infinite-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_infinite" class="fn">is_infinite</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.is_finite-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.is_finite-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_finite" class="fn">is_finite</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.is_normal-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.is_normal-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_normal" class="fn">is_normal</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.classify" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.classify" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.classify" class="fn">classify</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/num/enum.FpCategory.html" title="enum core::num::FpCategory">FpCategory</a></h4></section><section id="method.is_sign_positive-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.is_sign_positive-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_sign_positive" class="fn">is_sign_positive</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.is_sign_negative-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.is_sign_negative-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_sign_negative" class="fn">is_sign_negative</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.min-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.min-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.min" class="fn">min</a>(self, other: Self) -> Self</h4></section><section id="method.max-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.max-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.max" class="fn">max</a>(self, other: Self) -> Self</h4></section><section id="method.recip-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.recip-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.recip" class="fn">recip</a>(self) -> Self</h4></section><section id="method.to_degrees" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.to_degrees" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.to_degrees" class="fn">to_degrees</a>(self) -> Self</h4></section><section id="method.to_radians" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#787-800">source</a><a href="#method.to_radians" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.to_radians" class="fn">to_radians</a>(self) -> Self</h4></section><section id="method.is_subnormal-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#803-805">source</a><a href="#method.is_subnormal-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_subnormal" class="fn">is_subnormal</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-FloatCore-for-f64" class="impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#835-898">source</a><a href="#impl-FloatCore-for-f64" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.FloatCore.html" title="trait num_traits::float::FloatCore">FloatCore</a> for <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.f64.html">f64</a></h3></section></summary><div class="impl-items"><section id="method.infinity-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#836-845">source</a><a href="#method.infinity-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.infinity" class="fn">infinity</a>() -> Self</h4></section><section id="method.neg_infinity-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#836-845">source</a><a href="#method.neg_infinity-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.neg_infinity" class="fn">neg_infinity</a>() -> Self</h4></section><section id="method.nan-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#836-845">source</a><a href="#method.nan-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.nan" class="fn">nan</a>() -> Self</h4></section><section id="method.neg_zero-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#836-845">source</a><a href="#method.neg_zero-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.neg_zero" class="fn">neg_zero</a>() -> Self</h4></section><section id="method.min_value-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#836-845">source</a><a href="#method.min_value-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.min_value" class="fn">min_value</a>() -> Self</h4></section><section id="method.min_positive_value-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#836-845">source</a><a href="#method.min_positive_value-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.min_positive_value" class="fn">min_positive_value</a>() -> Self</h4></section><section id="method.epsilon-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#836-845">source</a><a href="#method.epsilon-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.epsilon" class="fn">epsilon</a>() -> Self</h4></section><section id="method.max_value-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#836-845">source</a><a href="#method.max_value-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.max_value" class="fn">max_value</a>() -> Self</h4></section><section id="method.integer_decode-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#848-850">source</a><a href="#method.integer_decode-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.integer_decode" class="fn">integer_decode</a>(self) -> (<a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.u64.html">u64</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.i16.html">i16</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.i8.html">i8</a>)</h4></section><section id="method.is_nan-2" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.is_nan-2" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_nan" class="fn">is_nan</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.is_infinite-2" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.is_infinite-2" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_infinite" class="fn">is_infinite</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.is_finite-2" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.is_finite-2" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_finite" class="fn">is_finite</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.is_normal-2" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.is_normal-2" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_normal" class="fn">is_normal</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.classify-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.classify-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.classify" class="fn">classify</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/num/enum.FpCategory.html" title="enum core::num::FpCategory">FpCategory</a></h4></section><section id="method.is_sign_positive-2" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.is_sign_positive-2" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_sign_positive" class="fn">is_sign_positive</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.is_sign_negative-2" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.is_sign_negative-2" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_sign_negative" class="fn">is_sign_negative</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section><section id="method.min-2" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.min-2" class="anchor">§</a><h4 class="code-header">fn <a href="#method.min" class="fn">min</a>(self, other: Self) -> Self</h4></section><section id="method.max-2" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.max-2" class="anchor">§</a><h4 class="code-header">fn <a href="#method.max" class="fn">max</a>(self, other: Self) -> Self</h4></section><section id="method.recip-2" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.recip-2" class="anchor">§</a><h4 class="code-header">fn <a href="#method.recip" class="fn">recip</a>(self) -> Self</h4></section><section id="method.to_degrees-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.to_degrees-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.to_degrees" class="fn">to_degrees</a>(self) -> Self</h4></section><section id="method.to_radians-1" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#852-865">source</a><a href="#method.to_radians-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.to_radians" class="fn">to_radians</a>(self) -> Self</h4></section><section id="method.is_subnormal-2" class="method trait-impl"><a class="src rightside" href="../../src/num_traits/float.rs.html#868-870">source</a><a href="#method.is_subnormal-2" class="anchor">§</a><h4 class="code-header">fn <a href="#method.is_subnormal" class="fn">is_subnormal</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/core/primitive.bool.html">bool</a></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../../trait.impl/num_traits/float/trait.FloatCore.js" data-ignore-extern-crates="core" async></script></section></div></main></body></html> |