<div dir="ltr"><div>So would it be to hamrfull to add at least this four operators? At the moment just allowing same Unit values. You mentioned that using Q_ASSERT is not a good idea, maybe there is another way of ensuring they have the same unit.<br><br>Value operator +(const Value &other) { <br>Q_ASSERT( this->unit() == other.unit() ); <br>return Value( this->number() + other.number() , this->unit() ); <br>}<br><br>Value operator -(const Value &other) { <br>Q_ASSERT( this->unit() == other.unit() ); <br>return Value( this->number() - other.number() , this->unit() ); <br>}<br><br>Value operator *(const double v) { <br>return Value( this->number() * v , this->unit() );<br>}<br><br>Value operator /(const double v) { <br>return Value( this->number() / v , this->unit() );<br>}<br><br></div><div>I think, this four operators could be really usefull and are pretty simple.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-11-21 22:59 GMT+01:00 Albert Astals Cid <span dir="ltr"><<a href="mailto:aacid@kde.org" target="_blank">aacid@kde.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">El dilluns, 21 de novembre de 2016, a les 18:00:18 CET, Christoph Feck va<br>
escriure:<br>
<div><div class="h5">> On 21.11.2016 08:27, Ander Pijoan wrote:<br>
> > Value operator +(const Value &other)<br>
> > {<br>
> ><br>
> >       Q_ASSERT( unit() == other.unit() );<br>
> >       return Value(  number() + other.number() , unit()  );<br>
> ><br>
> > }<br>
><br>
> So when adding "3 m" and "40 cm" you want to have an assert (that isn't<br>
> compiled into code unless you are in debug builds)?<br>
><br>
> Also, for multiplication, you would need to add all relationships<br>
> between units, so that "40 mph" * "30 min" would result in "20 miles".<br>
><br>
> This is especially problematic for temporary units, e.g. "40 kg" * "20<br>
> m/s" * "30 Hz" should have a "Newton" unit result, but just multiplying<br>
> mass and speed has no unit assigned in KUnitConversion.<br>
<br>
</div></div>We have a InvalidUnit, you can always default to that for stuff "you don't<br>
know".<br>
<br>
Cheers,<br>
  Albert<br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(68,68,68)"><font size="2"><span style="font-family:Arial;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">Ander Pijoan </span></font></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(68,68,68)"><font size="2"><span style="font-family:Arial;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">Research Assistant / DeustoTech Energía<br></span></font></span></p><span style="color:rgb(68,68,68)"><font size="2"><br></font></span><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(68,68,68)"><font size="2"><span style="font-family:Arial;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">Universidad de Deusto / Deustuko Unibertsitatea</span></font></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(68,68,68)"><font size="2"><span style="font-family:Arial;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">Avda. Universidades 24. 48007 Bilbao</span></font></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(68,68,68)"><font size="2"><span style="font-family:Arial;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">Tel. 94 413 90 03/ 2052<br></span></font></span></p><span style="color:rgb(68,68,68)"><font size="2"><span style="font-family:Arial;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"><a href="mailto:ander.pijoan@deusto.es" target="_blank">ander.pijoan@deusto.es</a></span></font></span></div></div></div></div></div></div>
</div>