LibrEDA project web page. https://libreda.codeberg.page
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

35 lines
12 KiB

<!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="Provides methods to compute the average of two integers, without overflows."><meta name="keywords" content="rust, rustlang, rust-lang, Average"><title>Average in num_integer - 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="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><script src="../crates.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></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="sidebar"><div class="sidebar-menu" role="button">&#9776;</div><a href='../num_integer/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><h2 class="location">Trait Average</h2><div class="sidebar-elems"><div class="block items"><h3 class="sidebar-title"><a href="#required-methods">Required Methods</a></h3><div class="sidebar-links"><a href="#tymethod.average_ceil">average_ceil</a><a href="#tymethod.average_floor">average_floor</a></div><h3 class="sidebar-title"><a href="#implementors">Implementors</a></h3></div><h2 class="location">Other items in<br><a href="index.html">num_integer</a></h2><div id="sidebar-vars" data-name="Average" data-ty="trait" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img src="../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../settings.html" title="settings"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Trait <a href="index.html">num_integer</a>::<wbr><a class="trait" href="#">Average</a><button id="copy-path" onclick="copy_path(this)" title="copy path"><img src="../clipboard.svg" width="19" height="18" alt="Copy item import" title="Copy item import to clipboard"></button></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/num_integer/average.rs.html#5-43" title="goto source code">[src]</a></span></h1><div class="docblock type-decl"><pre class="rust trait">pub trait Average: <a class="trait" href="trait.Integer.html" title="trait num_integer::Integer">Integer</a> {
fn <a href="#tymethod.average_ceil" class="fnname">average_ceil</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&amp;</a>Self) -&gt; Self;
<div class="item-spacer"></div> fn <a href="#tymethod.average_floor" class="fnname">average_floor</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&amp;</a>Self) -&gt; Self;
}</pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Provides methods to compute the average of two integers, without overflows.</p>
</div></details><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle" open><summary><div id="tymethod.average_ceil" class="method has-srclink"><h4 class="code-header">fn <a href="#tymethod.average_ceil" class="fnname">average_ceil</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&amp;</a>Self) -&gt; Self</h4><a class="srclink" href="../src/num_integer/average.rs.html#23" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Returns the ceiling value of the average of <code>self</code> and <code>other</code>.
<code>⌈(self + other)/2⌉</code></p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_integer::Average</span>;
<span class="macro">assert_eq!</span>(( <span class="number">3</span>).<span class="ident">average_ceil</span>(<span class="kw-2">&amp;</span><span class="number">10</span>), <span class="number">7</span>);
<span class="macro">assert_eq!</span>((<span class="op">-</span><span class="number">2</span>).<span class="ident">average_ceil</span>(<span class="kw-2">&amp;</span><span class="op">-</span><span class="number">5</span>), <span class="op">-</span><span class="number">3</span>);
<span class="macro">assert_eq!</span>(( <span class="number">4</span>).<span class="ident">average_ceil</span>(<span class="op">&amp;</span> <span class="number">4</span>), <span class="number">4</span>);
<span class="macro">assert_eq!</span>(<span class="ident">u8::max_value</span>().<span class="ident">average_ceil</span>(<span class="kw-2">&amp;</span><span class="number">2</span>), <span class="number">129</span>);
<span class="macro">assert_eq!</span>(<span class="ident">i8::min_value</span>().<span class="ident">average_ceil</span>(<span class="kw-2">&amp;</span><span class="op">-</span><span class="number">1</span>), <span class="op">-</span><span class="number">64</span>);
<span class="macro">assert_eq!</span>(<span class="ident">i8::min_value</span>().<span class="ident">average_ceil</span>(<span class="kw-2">&amp;</span><span class="ident">i8::max_value</span>()), <span class="number">0</span>);</pre></div>
</div></details><details class="rustdoc-toggle" open><summary><div id="tymethod.average_floor" class="method has-srclink"><h4 class="code-header">fn <a href="#tymethod.average_floor" class="fnname">average_floor</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&amp;</a>Self) -&gt; Self</h4><a class="srclink" href="../src/num_integer/average.rs.html#42" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Returns the floor value of the average of <code>self</code> and <code>other</code>.
<code>⌊(self + other)/2⌋</code></p>
<h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_integer::Average</span>;
<span class="macro">assert_eq!</span>(( <span class="number">3</span>).<span class="ident">average_floor</span>(<span class="kw-2">&amp;</span><span class="number">10</span>), <span class="number">6</span>);
<span class="macro">assert_eq!</span>((<span class="op">-</span><span class="number">2</span>).<span class="ident">average_floor</span>(<span class="kw-2">&amp;</span><span class="op">-</span><span class="number">5</span>), <span class="op">-</span><span class="number">4</span>);
<span class="macro">assert_eq!</span>(( <span class="number">4</span>).<span class="ident">average_floor</span>(<span class="op">&amp;</span> <span class="number">4</span>), <span class="number">4</span>);
<span class="macro">assert_eq!</span>(<span class="ident">u8::max_value</span>().<span class="ident">average_floor</span>(<span class="kw-2">&amp;</span><span class="number">2</span>), <span class="number">128</span>);
<span class="macro">assert_eq!</span>(<span class="ident">i8::min_value</span>().<span class="ident">average_floor</span>(<span class="kw-2">&amp;</span><span class="op">-</span><span class="number">1</span>), <span class="op">-</span><span class="number">65</span>);
<span class="macro">assert_eq!</span>(<span class="ident">i8::min_value</span>().<span class="ident">average_floor</span>(<span class="kw-2">&amp;</span><span class="ident">i8::max_value</span>()), <span class="op">-</span><span class="number">1</span>);</pre></div>
</div></details></div><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><details class="rustdoc-toggle implementors-toggle"><summary><div id="impl-Average" class="impl has-srclink"><h3 class="code-header in-band">impl&lt;I&gt; <a class="trait" href="trait.Average.html" title="trait num_integer::Average">Average</a> for I <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="trait.Integer.html" title="trait num_integer::Integer">Integer</a> + <a class="trait" href="https://doc.rust-lang.org/1.54.0/core/ops/bit/trait.Shr.html" title="trait core::ops::bit::Shr">Shr</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.usize.html">usize</a>, Output = I&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&amp;'a </a>I: <a class="trait" href="https://doc.rust-lang.org/1.54.0/core/ops/bit/trait.BitAnd.html" title="trait core::ops::bit::BitAnd">BitAnd</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&amp;'b </a>I, Output = I&gt; + <a class="trait" href="https://doc.rust-lang.org/1.54.0/core/ops/bit/trait.BitOr.html" title="trait core::ops::bit::BitOr">BitOr</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&amp;'b </a>I, Output = I&gt; + <a class="trait" href="https://doc.rust-lang.org/1.54.0/core/ops/bit/trait.BitXor.html" title="trait core::ops::bit::BitXor">BitXor</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&amp;'b </a>I, Output = I&gt;,&nbsp;</span></h3><a href="#impl-Average" class="anchor"></a><a class="srclink" href="../src/num_integer/average.rs.html#45-65" title="goto source code">[src]</a></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.average_floor" class="method trait-impl has-srclink"><h4 class="code-header">fn <a href="#tymethod.average_floor" class="fnname">average_floor</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&amp;</a>I) -&gt; I</h4><a href="#method.average_floor" class="anchor"></a><a class="srclink" href="../src/num_integer/average.rs.html#56-58" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Returns the floor value of the average of <code>self</code> and <code>other</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.average_ceil" class="method trait-impl has-srclink"><h4 class="code-header">fn <a href="#tymethod.average_ceil" class="fnname">average_ceil</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.54.0/std/primitive.reference.html">&amp;</a>I) -&gt; I</h4><a href="#method.average_ceil" class="anchor"></a><a class="srclink" href="../src/num_integer/average.rs.html#62-64" title="goto source code">[src]</a></div></summary><div class="docblock"><p>Returns the ceil value of the average of <code>self</code> and <code>other</code>.</p>
</div></details></div></details></div><script type="text/javascript" src="../implementors/num_integer/trait.Average.js" async></script></section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="num_integer" data-search-index-js="../search-index.js" data-search-js="../search.js"></div><script src="../main.js"></script></body></html>