Solved it this way:

si::dimensionless unscaled;
double f = conversion_factor(u,unscaled);
if (f < 1)
{
     int64_t intf = static_cast<int64_t>(1.0/f + 0.5);
     return val.value()/intf;
}
else
{
     int64_t intf = static_cast<int64_t>(f + 0.5);
     return val.value()*intf;
}

I can understand why double was chosen for scaling, but it doesn't "feel" right. Oh well, this will do for now.


On Mon, Feb 17, 2014 at 11:17 AM, Steven Watanabe <watanabesj@gmail.com> wrote:
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@gmail.com> 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 mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users