« Return to Thread: Units of data

Re: Units of data

by Steven Watanabe-4 :: Rate this Message:

Reply to Author | View in Thread

AMDG

Zachary Turner wrote:

> On Thu, Jul 2, 2009 at 2:07 PM, Steven Watanabe<watanabesj@...> wrote:
>  
>> AMDG
>>
>> Zachary Turner wrote:
>>    
>>> Thanks for your help so far!  I know I'm probably just making this too
>>> difficult, but it's still not working.  I guess I should just post a
>>> complete sample so that we can eliminate the snip factor from the list
>>> of possible causes  (I put them in the boost namespace for the sake of
>>> consistency but the same problem arises regardless).
>>>
>>> <snip>
>>>  void foo()
>>> {
>>>        using boost::units::quantity;
>>>        using namespace boost::units::data_capacity;
>>>
>>>        //Both of these fail with the message that there is no
>>> conversion to the destination
>>>        //type because the construcor is explicit
>>>        quantity<data_capacity> compressed_size = 1000 * bytes;
>>>        quantity<data_capacity, int> compressed_size2 = 1000 * bytes;
>>>
>>>      
>> Implicit conversion between different units is not allowed.
>> Try
>> quantity<data_capacity> compressed_size(1000 * bytes);
>>    
>
> Thanks.  The confusion came from the fact that the syntax I was trying
> was being used in some of the examples.  But there is something
> different about those examples, so that's why it wasn't working.  One
> of the trig examples has a line:
>
> quantity<plane_angle>           theta = 0.375*radians;
>
> for example.   I suppose it's due to the fact that radians are the
> "primary" unit for this dimension?
>  

The difference is that plane_angle is the same unit as radians.
In your case, data_capacity is defined as bits, while you are
assigning it a value in bytes.  Since the units change, the conversion
is explicit.

> That aside, I still think something isn't exactly right.  Ultimately I
> need to be able to print these quantities in different units (for
> example, if I'm transferring data at 100MB/s I don't want to print
> this in bits / second).  All of these seems to only allow printing of
> a quantity in its base unit, which here is defined to be bits.  I'd
> like to be able to do something like:
>
> quantity<capacity> q = 2180321.0 * bytes;
> std::cout << q * megabytes << std::endl;
>  

The units of q are bits.  Thus, the units of the expression that
you are printing are bits * megabytes which is printed as "b MB"

> It seems like this should "just work" since I've defined them all as
> scaled based units, but instead the first example just prints
>
> 1.74426e+007 b MB
>
> which means all its doing is formatting it as bits and then appending "MB"

In Christ,
Steven Watanabe

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

 « Return to Thread: Units of data