Boost logo

Boost Users :

Subject: Re: [Boost-users] [Units] Un-scaling dimensionless value
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2014-02-18 00:22:45


On 18/02/2014 11:18, Quoth Lindley French:
> I also think it's a design flaw to allow dimensionless units to have a
> scale factor, by the way. Ideally, that would be backed out
> automatically in the dimensionless case.

I must admit that one can be quite annoying. There's a default
conversion between an unscaled dimensionless quantity and the value type
of the quantity but this is not valid for scaled dimensionless
quantities. There was a thread about this a little while ago.

It's not really a problem if you're doing all calculations using
Boost.Units quantities and then simply printing the result, but it can
bite you if you want to pass that as a raw value to some external API
(which is probably the more common case in real-world code).

I think the "right way" to do it (according to Boost.Units logic) is to
define a system that has your target unit as a base unit, such that when
you move the unit from one system to another it automatically rescales
it to become the "real" value that you actually want, and you can get an
unscaled dimensionless value out of it. It's a little annoying, but
it's not actually all that much code.

(Though as Steven said this won't help in your case because rescaling
requires doubles, and rational<> doesn't support that.)


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net