[KUnitConversion] Question about overloading operators

Ander Pijoan ander.pijoan at deusto.es
Mon Nov 21 17:38:25 UTC 2016


I wasn't expecting to have different Units operations and conversion at
math operation.

Just same Unit category math operations, now it is no possible to sum or
subtract two VALUES whatever their unit is because the operator is not
overloaded. Just to be able to do "10m" + "20m" which is not possible right
now and I think it pretty straightforward and usefull for all.

2016-11-21 18:00 GMT+01:00 Christoph Feck <cfeck at kde.org>:

> On 21.11.2016 08:27, Ander Pijoan wrote:
>
>> Value operator +(const Value &other)
>> {
>>       Q_ASSERT( unit() == other.unit() );
>>       return Value(  number() + other.number() , unit()  );
>> }
>>
>
> So when adding "3 m" and "40 cm" you want to have an assert (that isn't
> compiled into code unless you are in debug builds)?
>
> Also, for multiplication, you would need to add all relationships between
> units, so that "40 mph" * "30 min" would result in "20 miles".
>
> This is especially problematic for temporary units, e.g. "40 kg" * "20
> m/s" * "30 Hz" should have a "Newton" unit result, but just multiplying
> mass and speed has no unit assigned in KUnitConversion.
>
>


-- 

Ander Pijoan

Research Assistant / DeustoTech EnergĂ­a

Universidad de Deusto / Deustuko Unibertsitatea

Avda. Universidades 24. 48007 Bilbao

Tel. 94 413 90 03/ 2052
ander.pijoan at deusto.es
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20161121/cb90015b/attachment-0001.html>


More information about the Kde-frameworks-devel mailing list