<!DOCTYPE html><htmllang='en'><head><title>[qty.arith.ops]</title><metacharset='UTF-8'/><linkrel='stylesheet'type='text/css'href='14882.css'/><linkrel='stylesheet'type='text/css'href='https://fonts.googleapis.com/css2?family=Noto+Serif'/><linkrel='stylesheet'type='text/css'href='https://fonts.googleapis.com/css2?family=Noto+Sans'/><linkrel='stylesheet'type='text/css'href='https://fonts.googleapis.com/css2?family=Noto+Sans+Mono'/><linkrel='icon'href='icon.png'/><linkrel='stylesheet'type='text/css'href='expanded.css'title='Normal'/><linkrel='alternate stylesheet'type='text/css'href='colored.css'title='Notes and examples colored'/><linkrel='alternate stylesheet'type='text/css'href='normative-only.css'title='Notes and examples hidden'/></head><body><divclass='wrapper'><h1><aclass='secnum'style='min-width:50pt'>5</a> Quantities and units library <aclass='abbr_ref'href='index.html#quantities'>[quantities]</a></h1><h2><aclass='secnum'style='min-width:65pt'>5.6</a> Quantity <aclass='abbr_ref'href='qty.html#arith.ops'>[qty]</a></h2><h3><aclass='secnum'style='min-width:80pt'>5.6.11</a> Arithmetic operations <aclass='abbr_ref'>[qty.arith.ops]</a></h3><divclass='para'id='1'><divclass='marginalizedparent'><aclass='marginalized'href='#1'>1</a></div><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L4983'>#</a></div><divclass='texpara'><divid='1.sentence-1'class='sentence'>In the following descriptions,
let <spanclass='texttt'>@</span> be the <spanclass='textsf'><i>operator</i></span><aclass='hidden_link'href='#1.sentence-1'>.</a></div></div></div><divclass='texpara'><divid='lib:quantity,operator%'><divid='lib:operator%,quantity'><divid='lib:quantity,operator-'><divid='lib:operator-,quantity'><divid='lib:quantity,operator+'><divid='lib:operator+,quantity'><divclass='itemdecl'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#lib:operator+,quantity'>🔗</a></div><codeclass='itemdeclcode'><spanclass='keyword'>template</span><spanclass='anglebracket'><</span>std<spanclass='operator'>::</span>derived_from<spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <spanclass='keyword'>auto</span> R2, <spanclass='keyword'>typename</span> Rep2<spanclass='anglebracket'>></span>
</code></div></div></div></div></div></div></div></div><divclass='para'id='2'><divclass='marginalizedparent'><aclass='marginalized'href='#2'>2</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L5004'>#</a></div><divclass='texpara'><divid='2.sentence-1'class='sentence'>Let <i>F</i> be the first argument to <aclass='index'id='conceptref:CommonlyInvocableQuantities___'></a><spanclass='texttt'><i>CommonlyInvocableQuantities</i></span><aclass='hidden_link'href='#2.sentence-1'>.</a></div></div></div></div><divclass='para'id='3'><divclass='marginalizedparent'><aclass='marginalized'href='#3'>3</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L5007'>#</a></div><divclass='texpara'><divid='3.sentence-1'class='sentence'><i>Preconditions</i>: If <spanclass='texttt'>@</span> is <spanclass='texttt'><spanclass='operator'>%</span></span>, then <spanclass='texttt'>is_<spanclass='shy'></span>neq_<spanclass='shy'></span>zero<spanclass='parenthesis'>(</span>rhs<spanclass='parenthesis'>)</span></span> is <spanclass='texttt'><spanclass='literal'>true</span></span><aclass='hidden_link'href='#3.sentence-1'>.</a></div></div></div></div><divclass='para'id='4'><divclass='marginalizedparent'><aclass='marginalized'href='#4'>4</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L5011'>#</a></div><divclass='texpara'><divid='4.sentence-1'class='sentence'><i>Effects</i>: Equivalent to:
</span></div></div></div></div><divclass='texpara'><divid='lib:quantity,operator%_'><divid='lib:operator%,quantity_'><divid='lib:quantity,operator-_'><divid='lib:operator-,quantity_'><divid='lib:quantity,operator+_'><divid='lib:operator+,quantity_'><divclass='itemdecl'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#lib:operator+,quantity_'>🔗</a></div><codeclass='itemdeclcode'><spanclass='keyword'>template</span><spanclass='anglebracket'><</span>std<spanclass='operator'>::</span>derived_from<spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <ahref='qty.rep.concepts.html#concept:Representation'title='5.5.4 Concepts [qty.rep.concepts]'><spanid='conceptref:Representation'><spanclass='texttt'>Representation</span></span></a> Value<spanclass='anglebracket'>></span>
<spanclass='keyword'>template</span><spanclass='anglebracket'><</span>std<spanclass='operator'>::</span>derived_from<spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <ahref='qty.rep.concepts.html#concept:Representation'title='5.5.4 Concepts [qty.rep.concepts]'><spanid='conceptref:Representation_'><spanclass='texttt'>Representation</span></span></a> Value<spanclass='anglebracket'>></span>
<spanclass='keyword'>template</span><spanclass='anglebracket'><</span>std<spanclass='operator'>::</span>derived_from<spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <ahref='qty.rep.concepts.html#concept:Representation'title='5.5.4 Concepts [qty.rep.concepts]'><spanid='conceptref:Representation__'><spanclass='texttt'>Representation</span></span></a> Value<spanclass='anglebracket'>></span>
</code></div></div></div></div></div></div></div></div><divclass='para'id='5'><divclass='marginalizedparent'><aclass='marginalized'href='#5'>5</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L5043'>#</a></div><divclass='texpara'><divid='5.sentence-1'class='sentence'><i>Effects</i>: Equivalent to:
<spanclass='keyword'>template</span><spanclass='anglebracket'><</span>std<spanclass='operator'>::</span>derived_from<spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <ahref='qty.rep.concepts.html#concept:Representation'title='5.5.4 Concepts [qty.rep.concepts]'><spanid='conceptref:Representation____'><spanclass='texttt'>Representation</span></span></a> Value<spanclass='anglebracket'>></span>
<spanclass='keyword'>template</span><spanclass='anglebracket'><</span>std<spanclass='operator'>::</span>derived_from<spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <ahref='qty.rep.concepts.html#concept:Representation'title='5.5.4 Concepts [qty.rep.concepts]'><spanid='conceptref:Representation_____'><spanclass='texttt'>Representation</span></span></a> Value<spanclass='anglebracket'>></span>
</code></div></div></div></div></div></div></div></div><divclass='para'id='6'><divclass='marginalizedparent'><aclass='marginalized'href='#6'>6</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L5068'>#</a></div><divclass='texpara'><divid='6.sentence-1'class='sentence'><i>Effects</i>: Equivalent to:
</code></div></div></div></div></div></div><divclass='para'id='7'><divclass='marginalizedparent'><aclass='marginalized'href='#7'>7</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L5086'>#</a></div><divclass='texpara'><divid='7.sentence-1'class='sentence'><i>Preconditions</i>: If <spanclass='texttt'>@</span> is <spanclass='texttt'><spanclass='operator'>/</span></span>, then <spanclass='texttt'>is_<spanclass='shy'></span>neq_<spanclass='shy'></span>zero<spanclass='parenthesis'>(</span>rhs<spanclass='parenthesis'>)</span></span> is <spanclass='texttt'><spanclass='literal'>true</span></span><aclass='hidden_link'href='#7.sentence-1'>.</a></div></div></div></div><divclass='para'id='8'><divclass='marginalizedparent'><aclass='marginalized'href='#8'>8</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L5090'>#</a></div><divclass='texpara'><divid='8.sentence-1'class='sentence'><i>Effects</i>: Equivalent to:
lhs<spanclass='operator'>.</span>numerical_value_ref_in<spanclass='parenthesis'>(</span>unit<spanclass='parenthesis'>)</span> @ rhs<spanclass='operator'>.</span>numerical_value_ref_in<spanclass='parenthesis'>(</span>rhs<spanclass='operator'>.</span>unit<spanclass='parenthesis'>)</span>, R @ R2<spanclass='curlybracket'>}</span>;
</span></div></div></div></div><divclass='texpara'><divid='lib:quantity,operator/_'><divid='lib:operator/,quantity_'><divid='lib:quantity,operator*_'><divid='lib:operator*,quantity_'><divclass='itemdecl'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#lib:operator*,quantity_'>🔗</a></div><codeclass='itemdeclcode'><spanclass='keyword'>template</span><spanclass='anglebracket'><</span>std<spanclass='operator'>::</span>derived_from<spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <spanclass='keyword'>typename</span> Value<spanclass='anglebracket'>></span>
<spanclass='keyword'>template</span><spanclass='anglebracket'><</span>std<spanclass='operator'>::</span>derived_from<spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <spanclass='keyword'>typename</span> Value<spanclass='anglebracket'>></span>
</code></div></div></div></div></div></div><divclass='para'id='9'><divclass='marginalizedparent'><aclass='marginalized'href='#9'>9</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L5113'>#</a></div><divclass='texpara'><divid='9.sentence-1'class='sentence'><i>Preconditions</i>: If <spanclass='texttt'>@</span> is <spanclass='texttt'><spanclass='operator'>/</span></span>, then <spanclass='texttt'>rhs <spanclass='operator'>!</span><spanclass='operator'>=</span> representation_<spanclass='shy'></span>values<spanclass='anglebracket'><</span>Value<spanclass='anglebracket'>></span><spanclass='operator'>​::​</span>zero<spanclass='parenthesis'>(</span><spanclass='parenthesis'>)</span></span> is <spanclass='texttt'><spanclass='literal'>true</span></span><aclass='hidden_link'href='#9.sentence-1'>.</a></div></div></div></div><divclass='para'id='10'><divclass='marginalizedparent'><aclass='marginalized'href='#10'>10</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L5117'>#</a></div><divclass='texpara'><divid='10.sentence-1'class='sentence'><i>Effects</i>: Equivalent to:
</code></div></div></div></div></div></div><divclass='para'id='11'><divclass='marginalizedparent'><aclass='marginalized'href='#11'>11</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L5139'>#</a></div><divclass='texpara'><divid='11.sentence-1'class='sentence'><i>Preconditions</i>: If <spanclass='texttt'>@</span> is <spanclass='texttt'><spanclass='operator'>/</span></span>, then <spanclass='texttt'>is_<spanclass='shy'></span>neq_<spanclass='shy'></span>zero<spanclass='parenthesis'>(</span>rhs<spanclass='parenthesis'>)</span></span> is <spanclass='texttt'><spanclass='literal'>true</span></span><aclass='hidden_link'href='#11.sentence-1'>.</a></div></div></div></div><divclass='para'id='12'><divclass='marginalizedparent'><aclass='marginalized'href='#12'>12</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L5143'>#</a></div><divclass='texpara'><divid='12.sentence-1'class='sentence'><i>Effects</i>: Equivalent to: