|
Boost : |
From: Jan Langer (jan_at_[hidden])
Date: 2003-10-25 05:43:14
Andy Little wrote:
>>and what should be the return type of an addition of kilometers and
>> inches.
>
> using your scheme I have absolutely no idea... :-)
as i already wrote i'd like to see a lib where everything is calculated
in measures of the fundamental unit. and i haven't tried to implement my
own units library. i really think there should be agreement on certain
basic design things. the existing librarys differ very much from each
other and each has certain ideas which might be good for ohers too.
> Try here for an answer:
> http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/index.html
i looked at the implementation and found the surprising answer that you
just take the units of the first operand. but consider the example:
kilometers + meters
a user might think that a value_type of int is sufficient for his needs.
then he adds 2 kilometers and 5 meters and he gets 2 kilometers. if he
does it the other way round he'll get 2005 meters. thats quite error-prone.
if he explicitly says "i want to calculate in kilometers" somewhere it
would be ok. because then also 5 meters plus 2 kilometers gives 2
kilometers.
jan
-- jan langer ... jan_at_[hidden] "pi ist genau drei"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk