Deployed 1d9a7c28 to HEAD with MkDocs 1.6.1 and mike 2.1.3

This commit is contained in:
github-actions
2025-06-17 14:21:09 +00:00
parent 4e9c622982
commit 86d0af388e
9 changed files with 99 additions and 47 deletions

View File

@ -2399,7 +2399,7 @@ You're not viewing the latest version.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 20a8 8 0 0 0 8-8 8 8 0 0 0-8-8 8 8 0 0 0-8 8 8 8 0 0 0 8 8m0-18a10 10 0 0 1 10 10 10 10 0 0 1-10 10C6.47 22 2 17.5 2 12A10 10 0 0 1 12 2m.5 5v5.25l4.5 2.67-.75 1.23L11 13V7z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 20a8 8 0 0 0 8-8 8 8 0 0 0-8-8 8 8 0 0 0-8 8 8 8 0 0 0 8 8m0-18a10 10 0 0 1 10 10 10 10 0 0 1-10 10C6.47 22 2 17.5 2 12A10 10 0 0 1 12 2m.5 5v5.25l4.5 2.67-.75 1.23L11 13V7z"/></svg>
<span class="md-ellipsis"> <span class="md-ellipsis">
7 min read 8 min read
</span> </span>
</div> </div>
@ -2489,6 +2489,15 @@ You're not viewing the latest version.
</span> </span>
</a> </a>
</li>
<li class="md-nav__item">
<a href="#motivating-example" class="md-nav__link">
<span class="md-ellipsis">
Motivating example
</span>
</a>
</li> </li>
</ul> </ul>
@ -2614,7 +2623,7 @@ in many equations in source code where it would be a good fit otherwise.</p>
(e.g., temperatures in degrees Celsius, tared mass measurements, altitudes above some (e.g., temperatures in degrees Celsius, tared mass measurements, altitudes above some
reference point, etc.) and do it really well. Constrained affine space arithmetic reference point, etc.) and do it really well. Constrained affine space arithmetic
(e.g., preventing accidental addition of points) also improves the safety of our programs. (e.g., preventing accidental addition of points) also improves the safety of our programs.
This is why it is a very valuable abstraction and should be used even more often than now.</p> This is why it is a valuable abstraction and should be used more even often than now.</p>
<p>To improve the user experience and open the doors for new features in the future, we are <p>To improve the user experience and open the doors for new features in the future, we are
considering adding a third abstraction for absolute quantities. In terms of properties, considering adding a third abstraction for absolute quantities. In terms of properties,
an absolute quantity will lie between points and deltas.</p> an absolute quantity will lie between points and deltas.</p>
@ -2661,7 +2670,7 @@ an absolute quantity will lie between points and deltas.</p>
<tr> <tr>
<td><strong>Relative to origin</strong></td> <td><strong>Relative to origin</strong></td>
<td style="text-align: center;">Absolute &amp; relative</td> <td style="text-align: center;">Absolute &amp; relative</td>
<td style="text-align: center;">Absolute (implicit only)</td> <td style="text-align: center;">Measured against nothing/void</td>
<td style="text-align: center;"><span class="twemoji"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 6.91 17.09 4 12 9.09 6.91 4 4 6.91 9.09 12 4 17.09 6.91 20 12 14.91 17.09 20 20 17.09 14.91 12z"/></svg></span></td> <td style="text-align: center;"><span class="twemoji"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 6.91 17.09 4 12 9.09 6.91 4 4 6.91 9.09 12 4 17.09 6.91 20 12 14.91 17.09 20 20 17.09 14.91 12z"/></svg></span></td>
</tr> </tr>
<tr> <tr>
@ -2687,23 +2696,22 @@ an absolute quantity will lie between points and deltas.</p>
<p>As we can see above, absolute quantities have only two limitations, and both are connected <p>As we can see above, absolute quantities have only two limitations, and both are connected
to the offset units' usage. They can't use those because they must remain absolute to the offset units' usage. They can't use those because they must remain absolute
instead of being measured relative to some custom origin.</p> instead of being measured relative to some custom origin.</p>
<p>It is also vital to notice that there will be no way to provide a custom origin for <p>Absolute quantities could be considered delta quantities that represent a whole
absolute quantities, even if it is defined in terms of <code>absolute_point_origin</code>. Those -- the entire entity being measured. This is why we can represent a system mass by adding
quantities are meant to model abstractions with well-established and unambiguous zero absolute masses of all system elements or a system energy by adding absolute
origins. If we allow passing absolute point origins, we could define two quantities temperatures of all the system elements.</p>
of the same type measured according to different not-related origins, which would be <p>As those are more related to deltas than points, it is impossible to specify their origin
too confusing.</p> points. This also allows us to print them, as we do not need any special text to describe
<p>The above also allows us to print them, as we do not need any special text to describe their origin as they are always measured against nothing/void.</p>
their origin.</p>
<h2 id="interfaces-refactoring">Interfaces refactoring<a class="headerlink" href="#interfaces-refactoring" title="Permanent link">&para;</a></h2> <h2 id="interfaces-refactoring">Interfaces refactoring<a class="headerlink" href="#interfaces-refactoring" title="Permanent link">&para;</a></h2>
<p>As I mentioned in my <a href="../../../01/15/bringing-quantity-safety-to-the-next-level/#should-we-get-rid-of-a-quantity_point">previous post</a>, <p>As I mentioned in my <a href="../../../01/15/bringing-quantity-safety-to-the-next-level/#should-we-get-rid-of-a-quantity_point">previous post</a>,
we are seriously considering removing <code>quantity_point</code> class template and replacing it with we are seriously considering removing <code>quantity_point</code> class template and replacing it with
a <code>quantity_spec</code> point wrapper. For example, <code>quantity_point&lt;isq::altitude[m]&gt;</code> will become a <code>quantity_spec</code> point wrapper. For example, <code>quantity_point&lt;isq::altitude[m]&gt;</code> will become
<code>quantity&lt;point&lt;isq::altitude[m]&gt;&gt;</code>.</p> <code>quantity&lt;point&lt;isq::altitude[m]&gt;&gt;</code>.</p>
<p>I initially planned <code>quantity&lt;isq::mass&gt;</code> to be the same as <code>quantity&lt;delta&lt;isq::mass&gt;&gt;</code>, <p>I initially planned <code>quantity&lt;isq::mass&gt;</code> to be the same as <code>quantity&lt;delta&lt;isq::mass&gt;&gt;</code>,
but it turns out that deltas probably should not be the default. It is consistent with how we but it turns out that deltas probably should not be the default. It is consistent with how
write physical expressions on paper, right? Delta symbol (∆) is always "verbose" we write physical expressions on paper, right? Delta symbol (∆) is always "verbose"
in our equations, it would be nice for the C++ code to do the same. So, deltas will always in physical equations, it would be nice for the C++ code to do the same. So, deltas will always
need to be explicit.</p> need to be explicit.</p>
<p>And this brings us to absolute quantities. They should actually be the default we are looking <p>And this brings us to absolute quantities. They should actually be the default we are looking
for. This is what we write as quantities in most of the physical equations. This is why we for. This is what we write as quantities in most of the physical equations. This is why we
@ -2732,16 +2740,15 @@ will not need any specifier to denote them.</p>
<p>Affine space arithmetic is well-defined. However, we are adding a new type to the library <p>Affine space arithmetic is well-defined. However, we are adding a new type to the library
that lands between points and deltas. This is why we must agree on the arithmetic for all that lands between points and deltas. This is why we must agree on the arithmetic for all
possible combinations.</p> possible combinations.</p>
<p>Let's try to define them here, assuming that points and absolute values share
a common origin.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If points and absolute values do not share a common absolute point origin
the operation should fail to compile.</p>
</div>
<h3 id="addition">Addition<a class="headerlink" href="#addition" title="Permanent link">&para;</a></h3> <h3 id="addition">Addition<a class="headerlink" href="#addition" title="Permanent link">&para;</a></h3>
<p>In case of addition, a more constrained type is preserved (except for adding two points, <p>Absolute quantities are deltas against nothing so adding them to a point yields another point.</p>
which is undefined):</p> <p>Adding a delta to them yields a delta, as a delta may represent only a part of something and
a whole, and a part is not a whole. The delta may also be negative and greater
than the absolute quantity, which may yield a negative value. This is why delta is a good
result here.</p>
<p>Only adding whole non-negative entities of the system yields a system being expressed as
an entire non-negative entity. This is why adding absolute quantities results in an absolute
quantity.</p>
<table> <table>
<thead> <thead>
<tr> <tr>
@ -2762,20 +2769,23 @@ which is undefined):</p>
<td><strong>Absolute</strong></td> <td><strong>Absolute</strong></td>
<td style="text-align: center;">Point</td> <td style="text-align: center;">Point</td>
<td style="text-align: center;">Absolute</td> <td style="text-align: center;">Absolute</td>
<td style="text-align: center;">Absolute</td> <td style="text-align: center;">Delta</td>
</tr> </tr>
<tr> <tr>
<td><strong>Delta</strong></td> <td><strong>Delta</strong></td>
<td style="text-align: center;">Point</td> <td style="text-align: center;">Point</td>
<td style="text-align: center;">Absolute</td> <td style="text-align: center;">Delta</td>
<td style="text-align: center;">Delta</td> <td style="text-align: center;">Delta</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<h3 id="subtraction">Subtraction<a class="headerlink" href="#subtraction" title="Permanent link">&para;</a></h3> <h3 id="subtraction">Subtraction<a class="headerlink" href="#subtraction" title="Permanent link">&para;</a></h3>
<p>Subtraction is more tricky. To verify the logic below, it might be helpful to ask whether <p>Similarly, during subtraction, regular affine space arithmetics for deltas apply.
a result may be negative when two arguments are non-negative. If the answer is true, Subtracting an absolute quantity from a point yields a point, and trying to do the opposite
the result should be a delta quantity.</p> does not make physical sense.</p>
<p>Subtracting two non-negative absolute quantities may yield a negative value if we subtract
a larger one from the smaller one, so the result should be a delta. A similar result
may be obtained by subtracting a delta from absolute quantity or absolute quantity from a delta.</p>
<table> <table>
<thead> <thead>
<tr> <tr>
@ -2794,9 +2804,9 @@ the result should be a delta quantity.</p>
</tr> </tr>
<tr> <tr>
<td><strong>Absolute</strong></td> <td><strong>Absolute</strong></td>
<td style="text-align: center;"><span class="twemoji"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 6.91 17.09 4 12 9.09 6.91 4 4 6.91 9.09 12 4 17.09 6.91 20 12 14.91 17.09 20 20 17.09 14.91 12z"/></svg></span></td>
<td style="text-align: center;">Delta</td> <td style="text-align: center;">Delta</td>
<td style="text-align: center;">Delta</td> <td style="text-align: center;">Delta</td>
<td style="text-align: center;">Absolute</td>
</tr> </tr>
<tr> <tr>
<td><strong>Delta</strong></td> <td><strong>Delta</strong></td>
@ -2806,29 +2816,71 @@ the result should be a delta quantity.</p>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<div class="admonition info">
<p class="admonition-title">Info</p>
<p>Based on the above assumptions, one of the lines of the below code can't compile:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">270</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">K</span><span class="p">;</span>
</span><span id="__span-3-2"><a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">point</span><span class="o">&lt;</span><span class="n">K</span><span class="o">&gt;</span><span class="p">(</span><span class="mi">300</span><span class="p">);</span><span class="w"> </span>
</span><span id="__span-3-3"><a id="__codelineno-3-3" name="__codelineno-3-3" href="#__codelineno-3-3"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">temp2</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">temp1</span><span class="p">;</span><span class="w"> </span><span class="c1">// Point</span>
</span><span id="__span-3-4"><a id="__codelineno-3-4" name="__codelineno-3-4" href="#__codelineno-3-4"></a><span class="c1">// quantity temp4 = temp1 - temp2; // Compile-time error</span>
</span><span id="__span-3-5"><a id="__codelineno-3-5" name="__codelineno-3-5" href="#__codelineno-3-5"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp5</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">temp1</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">temp2</span><span class="p">.</span><span class="n">absolute</span><span class="p">();</span><span class="w"> </span><span class="c1">// Delta</span>
</span></code></pre></div>
</div>
<h3 id="motivating-example">Motivating example<a class="headerlink" href="#motivating-example" title="Permanent link">&para;</a></h3>
<p>Let's consider a room with a table and two glasses filled with fluid on top of it.
Let's also assume that we want to stack one on top of the other and treat them as a system
we observe.</p>
<p><img alt="Absolute quantities" src="../../../../absolute-quantities.jpeg" width="500" /></p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="c1">// absolute quantities</span>
</span><span id="__span-4-2"><a id="__codelineno-4-2" name="__codelineno-4-2" href="#__codelineno-4-2"></a><span class="n">quantity</span><span class="o">&lt;</span><span class="n">isq</span><span class="o">::</span><span class="n">height</span><span class="p">[</span><span class="n">cm</span><span class="p">]</span><span class="o">&gt;</span><span class="w"> </span><span class="n">glass1_height</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">20</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">cm</span><span class="p">;</span>
</span><span id="__span-4-3"><a id="__codelineno-4-3" name="__codelineno-4-3" href="#__codelineno-4-3"></a><span class="n">quantity</span><span class="o">&lt;</span><span class="n">isq</span><span class="o">::</span><span class="n">height</span><span class="p">[</span><span class="n">cm</span><span class="p">]</span><span class="o">&gt;</span><span class="w"> </span><span class="n">glass2_height</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">15</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">cm</span><span class="p">;</span>
</span><span id="__span-4-4"><a id="__codelineno-4-4" name="__codelineno-4-4" href="#__codelineno-4-4"></a>
</span><span id="__span-4-5"><a id="__codelineno-4-5" name="__codelineno-4-5" href="#__codelineno-4-5"></a><span class="c1">// delta quantities</span>
</span><span id="__span-4-6"><a id="__codelineno-4-6" name="__codelineno-4-6" href="#__codelineno-4-6"></a><span class="n">quantity</span><span class="o">&lt;</span><span class="n">delta</span><span class="o">&lt;</span><span class="n">isq</span><span class="o">::</span><span class="n">height</span><span class="o">&gt;</span><span class="p">[</span><span class="n">cm</span><span class="p">]</span><span class="o">&gt;</span><span class="w"> </span><span class="n">fluid_level</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">16</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">cm</span><span class="p">;</span>
</span><span id="__span-4-7"><a id="__codelineno-4-7" name="__codelineno-4-7" href="#__codelineno-4-7"></a>
</span><span id="__span-4-8"><a id="__codelineno-4-8" name="__codelineno-4-8" href="#__codelineno-4-8"></a><span class="c1">// point quantities</span>
</span><span id="__span-4-9"><a id="__codelineno-4-9" name="__codelineno-4-9" href="#__codelineno-4-9"></a><span class="kr">inline</span><span class="w"> </span><span class="k">constexpr</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">floor_level</span><span class="w"> </span><span class="k">final</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">absolute_point_origin</span><span class="o">&lt;</span><span class="n">isq</span><span class="o">::</span><span class="n">height</span><span class="o">&gt;</span><span class="w"> </span><span class="n">floor_level</span><span class="p">;</span>
</span><span id="__span-4-10"><a id="__codelineno-4-10" name="__codelineno-4-10" href="#__codelineno-4-10"></a><span class="n">quantity</span><span class="o">&lt;</span><span class="n">point</span><span class="o">&lt;</span><span class="n">isq</span><span class="o">::</span><span class="n">height</span><span class="p">[</span><span class="n">cm</span><span class="p">],</span><span class="w"> </span><span class="n">floor_level</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="n">table_top</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">floor_level</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">m</span><span class="p">;</span>
</span><span id="__span-4-11"><a id="__codelineno-4-11" name="__codelineno-4-11" href="#__codelineno-4-11"></a><span class="c1">// quantity&lt;point&lt;isq::height[cm]&gt;&gt; glass1_top(glass1_height); // point against nothing (no length)</span>
</span><span id="__span-4-12"><a id="__codelineno-4-12" name="__codelineno-4-12" href="#__codelineno-4-12"></a>
</span><span id="__span-4-13"><a id="__codelineno-4-13" name="__codelineno-4-13" href="#__codelineno-4-13"></a><span class="c1">// absolute results</span>
</span><span id="__span-4-14"><a id="__codelineno-4-14" name="__codelineno-4-14" href="#__codelineno-4-14"></a><span class="n">quantity</span><span class="w"> </span><span class="n">system_height</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">glass1_height</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">glass2_height</span><span class="p">;</span>
</span><span id="__span-4-15"><a id="__codelineno-4-15" name="__codelineno-4-15" href="#__codelineno-4-15"></a>
</span><span id="__span-4-16"><a id="__codelineno-4-16" name="__codelineno-4-16" href="#__codelineno-4-16"></a><span class="c1">// delta results</span>
</span><span id="__span-4-17"><a id="__codelineno-4-17" name="__codelineno-4-17" href="#__codelineno-4-17"></a><span class="n">quantity</span><span class="w"> </span><span class="n">empty_height_res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">glass1_height</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">fluid_level</span><span class="p">;</span>
</span><span id="__span-4-18"><a id="__codelineno-4-18" name="__codelineno-4-18" href="#__codelineno-4-18"></a><span class="n">quantity</span><span class="w"> </span><span class="n">glass2_height_res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">system_height</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">glass1_height</span><span class="p">;</span><span class="w"> </span><span class="c1">// could result in an absolute quantity</span>
</span><span id="__span-4-19"><a id="__codelineno-4-19" name="__codelineno-4-19" href="#__codelineno-4-19"></a><span class="n">assert</span><span class="p">(</span><span class="n">glass2_height_res</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">glass2_height</span><span class="p">);</span>
</span><span id="__span-4-20"><a id="__codelineno-4-20" name="__codelineno-4-20" href="#__codelineno-4-20"></a><span class="n">quantity</span><span class="w"> </span><span class="n">height_diff_res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">glass2_height</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">glass1_height</span><span class="p">;</span><span class="w"> </span><span class="c1">// but this one should definitely return delta</span>
</span><span id="__span-4-21"><a id="__codelineno-4-21" name="__codelineno-4-21" href="#__codelineno-4-21"></a>
</span><span id="__span-4-22"><a id="__codelineno-4-22" name="__codelineno-4-22" href="#__codelineno-4-22"></a><span class="c1">// point results</span>
</span><span id="__span-4-23"><a id="__codelineno-4-23" name="__codelineno-4-23" href="#__codelineno-4-23"></a><span class="n">quantity</span><span class="o">&lt;</span><span class="n">point</span><span class="o">&lt;</span><span class="n">isq</span><span class="o">::</span><span class="n">height</span><span class="p">[</span><span class="n">cm</span><span class="p">],</span><span class="w"> </span><span class="n">floor_level</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="n">glass1_top</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">table_top</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">glass1_height</span><span class="p">;</span>
</span><span id="__span-4-24"><a id="__codelineno-4-24" name="__codelineno-4-24" href="#__codelineno-4-24"></a><span class="n">quantity</span><span class="w"> </span><span class="n">point1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">glass1_top</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">glass1_height</span><span class="p">;</span>
</span><span id="__span-4-25"><a id="__codelineno-4-25" name="__codelineno-4-25" href="#__codelineno-4-25"></a><span class="n">assert</span><span class="p">(</span><span class="n">point1</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">table_top</span><span class="p">);</span>
</span><span id="__span-4-26"><a id="__codelineno-4-26" name="__codelineno-4-26" href="#__codelineno-4-26"></a><span class="c1">// quantity point2 = glass1_height - glass1_top;      // no sense - does not compile</span>
</span></code></pre></div>
<h2 id="new-opportunities">New opportunities<a class="headerlink" href="#new-opportunities" title="Permanent link">&para;</a></h2> <h2 id="new-opportunities">New opportunities<a class="headerlink" href="#new-opportunities" title="Permanent link">&para;</a></h2>
<p>The new syntax simplifies API as one <code>quantity</code> class template will now serve all quantity <p>The new syntax simplifies API as one <code>quantity</code> class template will now serve all quantity
variations (possibly even more in the future). It also allows us to model quantities that variations (possibly even more in the future). It also allows us to model quantities that
were impossible to express before without some workarounds.</p> were impossible to express before without some workarounds.</p>
<p>For example, we can now correctly calculate Carnot engine efficiency with any of the following:</p> <p>For example, we can now correctly calculate Carnot engine efficiency with any of the following:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp_cold</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">300.</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">K</span><span class="p">;</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-5-1"><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp_cold</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">300.</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">K</span><span class="p">;</span>
</span><span id="__span-3-2"><a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp_hot</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">500.</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">K</span><span class="p">;</span> </span><span id="__span-5-2"><a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp_hot</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">500.</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">K</span><span class="p">;</span>
</span><span id="__span-3-3"><a id="__codelineno-3-3" name="__codelineno-3-3" href="#__codelineno-3-3"></a><span class="n">quantity</span><span class="w"> </span><span class="n">carnot_eff_1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1.</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">temp_cold</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">temp_hot</span><span class="p">;</span> </span><span id="__span-5-3"><a id="__codelineno-5-3" name="__codelineno-5-3" href="#__codelineno-5-3"></a><span class="n">quantity</span><span class="w"> </span><span class="n">carnot_eff_1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1.</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">temp_cold</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">temp_hot</span><span class="p">;</span>
</span><span id="__span-3-4"><a id="__codelineno-3-4" name="__codelineno-3-4" href="#__codelineno-3-4"></a><span class="n">quantity</span><span class="w"> </span><span class="n">carnot_eff_2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">temp_hot</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">temp_cold</span><span class="p">)</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">temp_hot</span><span class="p">;</span> </span><span id="__span-5-4"><a id="__codelineno-5-4" name="__codelineno-5-4" href="#__codelineno-5-4"></a><span class="n">quantity</span><span class="w"> </span><span class="n">carnot_eff_2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">temp_hot</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">temp_cold</span><span class="p">)</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">temp_hot</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<p>In the above code, we can easily create absolute or delta values of temperatures and do <p>In the above code, we can easily create absolute or delta values of temperatures and do
arithmetics on them. Previously, we had to create deltas from both points artificially arithmetics on them. Previously, we had to create deltas from both points artificially
with:</p> with:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp_cold</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">point</span><span class="o">&lt;</span><span class="n">K</span><span class="o">&gt;</span><span class="p">(</span><span class="mf">300.</span><span class="p">);</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp_cold</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">point</span><span class="o">&lt;</span><span class="n">K</span><span class="o">&gt;</span><span class="p">(</span><span class="mf">300.</span><span class="p">);</span>
</span><span id="__span-4-2"><a id="__codelineno-4-2" name="__codelineno-4-2" href="#__codelineno-4-2"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp_hot</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">point</span><span class="o">&lt;</span><span class="n">K</span><span class="o">&gt;</span><span class="p">(</span><span class="mf">500.</span><span class="p">);</span> </span><span id="__span-6-2"><a id="__codelineno-6-2" name="__codelineno-6-2" href="#__codelineno-6-2"></a><span class="n">quantity</span><span class="w"> </span><span class="n">temp_hot</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">point</span><span class="o">&lt;</span><span class="n">K</span><span class="o">&gt;</span><span class="p">(</span><span class="mf">500.</span><span class="p">);</span>
</span><span id="__span-4-3"><a id="__codelineno-4-3" name="__codelineno-4-3" href="#__codelineno-4-3"></a><span class="n">quantity</span><span class="w"> </span><span class="n">carnot_eff_1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1.</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">temp_cold</span><span class="p">.</span><span class="n">quantity_from_zero</span><span class="p">()</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">temp_hot</span><span class="p">.</span><span class="n">quantity_from_zero</span><span class="p">();</span> </span><span id="__span-6-3"><a id="__codelineno-6-3" name="__codelineno-6-3" href="#__codelineno-6-3"></a><span class="n">quantity</span><span class="w"> </span><span class="n">carnot_eff_1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1.</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">temp_cold</span><span class="p">.</span><span class="n">quantity_from_zero</span><span class="p">()</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">temp_hot</span><span class="p">.</span><span class="n">quantity_from_zero</span><span class="p">();</span>
</span><span id="__span-4-4"><a id="__codelineno-4-4" name="__codelineno-4-4" href="#__codelineno-4-4"></a><span class="n">quantity</span><span class="w"> </span><span class="n">carnot_eff_2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">temp_hot</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">temp_cold</span><span class="p">)</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">temp_hot</span><span class="p">.</span><span class="n">quantity_from_zero</span><span class="p">();</span> </span><span id="__span-6-4"><a id="__codelineno-6-4" name="__codelineno-6-4" href="#__codelineno-6-4"></a><span class="n">quantity</span><span class="w"> </span><span class="n">carnot_eff_2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">temp_hot</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">temp_cold</span><span class="p">)</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">temp_hot</span><span class="p">.</span><span class="n">quantity_from_zero</span><span class="p">();</span>
</span></code></pre></div> </span></code></pre></div>
<p>It worked but was far from being physically pure and pretty.</p> <p>It worked but was far from being physically pure and pretty.</p>
<h2 id="summary">Summary<a class="headerlink" href="#summary" title="Permanent link">&para;</a></h2> <h2 id="summary">Summary<a class="headerlink" href="#summary" title="Permanent link">&para;</a></h2>
<p>We believe that adding absolute quantities will be a major improvement in the library that <p>We believe that adding absolute quantities will be a significant improvement in the library
will allow us to more correctly model physical equations making them terser and easier to that will allow us to model physical equations in a terser, more correct, easier to
understand at the same time.</p> write, understand, and maintain way.</p>
<p>We plan to deliver the features mentioned in this post as a part of <strong>mp-units</strong> V3.</p> <p>We plan to deliver the features mentioned in this post as a part of <strong>mp-units</strong> V3.</p>
<p>Please share your feedback.</p> <p>Please share your feedback.</p>

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

View File

@ -2375,7 +2375,7 @@ You're not viewing the latest version.
<li class="md-meta__item"> <li class="md-meta__item">
7 min read 8 min read
</li> </li>

View File

@ -2375,7 +2375,7 @@ You're not viewing the latest version.
<li class="md-meta__item"> <li class="md-meta__item">
7 min read 8 min read
</li> </li>

View File

@ -2361,7 +2361,7 @@ You're not viewing the latest version.
<li class="md-meta__item"> <li class="md-meta__item">
7 min read 8 min read
</li> </li>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long