Boost logo

Boost Users :

Subject: Re: [Boost-users] [Units] Un-scaling dimensionless value
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2014-02-17 11:17:25


AMDG

On 02/17/2014 07:40 AM, Lindley French wrote:
> For the life of me I can't figure out where the actual multiplication of
> the value occurs. Boost Units is very clever template magic, but I doubt
> anyone could maintain the thing without weeks of studying the design....
>

detail/conversion_impl.hpp:345

return(destination_type::from_value(static_cast<T2>(source.value() *
conversion_factor(u1, u2))));

This won't really help you because
the result of conversion_factor
returns a double.

The scale is evaluated at detail/conversion_impl.hpp:448
        return(conversion1::value() * (scale::value() /
conversion2::value()));

"scale" here is the result of get_scale_list/eval_scale_list.
get_scale_list collects the scaling factors, eval_scale_list
multiplies their ::value() together.

Again, scale::value() returns a double, because the
individual scale factors use double. (See scale.hpp)

>
> On Mon, Feb 17, 2014 at 9:48 AM, Lindley French <lindleyf_at_[hidden]> wrote:
>
>> What's the best way to access the current scaling of a dimensionless
>> value? Maybe I can back it out myself rather than relying on type
>> conversion to do it.
>>

There's a metafunction called get_scale_list,
which returns an MPL sequence whose members
contain

static const long base = ...;
typedef static_rational<...> exponent;

It's not documented, so use it at your own risk.
It's unlikely to change, but I make no guarantees.

In Christ,
Steven Watanabe


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