Boost logo

Boost Users :

Subject: Re: [Boost-users] [Units] Un-scaling dimensionless value
From: Lindley French (lindleyf_at_[hidden])
Date: 2014-02-16 14:08:00


I find it very surprising that the conversion would use floating point, since scaled units use static_rational. Are you certain that's how it works?

> On Feb 14, 2014, at 8:27 PM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
>
> AMDG
>
>> On 02/14/2014 04:06 PM, Lindley French wrote:
>> <snip>
>> Now, when I cout these values, I see that everything is technically the
>> correct. The problem is that total is a dimensionless quantity which is
>> scaled----it's 1,250,000,000, when I expect 1,250,000, and it displays as
>> "1250000000 m", where m is "milli", not "meters".
>>
>> What is the correct way to un-scale dimensionless quantities? I tried this:
>> quantity<si::dimensionless,rational<unsigned>> unscaled(total);
>>
>> However, unscaled still has the same value.
>
> The result comes out as zero for me.
>
>> I also tried
>> typedef make_scaled_unit<si::dimensionless, scale<10, static_rational<0> >
>>> ::type dimensionless_unit;
>> quantity<dimensionless_unit,rational<unsigned>> unscaled(total);
>>
>> but this time, unscaled came out zero.
>>
>> Any suggestions?
>
> The reason it's zero comes down to:
>
> std::cout << rational<unsigned>(1250000000) * 0.001 << std::endl;
> // prints 0/1
>
> Conversions involving rational do not work
> correctly, because rational does not support
> multiplication by double.
>
> In Christ,
> Steven Watanabe
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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