Boost logo

Boost :

Subject: Re: [boost] [units] - learning to use, more questions :)
From: Janek Kozicki (janek_listy_at_[hidden])
Date: 2011-11-28 19:15:44


Matthias Schabel said: (by the date of Mon, 28 Nov 2011 14:13:55 -0800)

> The first line compiles correctly using Boost 1.48; I don't know when the fix was made.

Thanks, I'll upgrade to 1.48 before going forward :)

> However, you also have an error in the second line; alpha is not a reciprocal_area : kg * (1/s) / (kg m^2/s)^1/2 = kg^1/2 s^-1/2 m^-1. Of course, this makes the third line incorrect as well; an example of the power of Boost.Units, I guess...

oh, yes. Definitely a power of Boost.Units, and the best reason to
use it! Indeed I have a mistake here. I had a little different
formula few pages back in my notebook, then I rewrote it to new place
intrudocing a mistake :)

> In general, when debugging units, it is often helpful to output to the console. Use of auto for intermediate values is also your friend... For example, here's what I did to figure out your problem:

thanks a lot, especially for the `auto` hint, which I totally forgot.

> Steven - since you implemented the constants.hpp header, I'm a little reluctant to rummage through it. Could you please consider
>
> 1) adding support for the pow<> and root<> operations?
> 2) deprecating constant.value_type and constant.value() in favor of constant.quantity_type and constant.quantity() or constant.mean_value() or constant.mean() or something?
>
> Also, can you remind me why we have "constant" and "physical_constant" structs? They look identical to me...

I'm looking forward to those improvements too :)

 
> Janek,
>
> I have attached headers implementing the various prefixed short cuts for the meter and joule; these two should be sufficient to extend to the rest of the SI unit system.

umm.. did you forget to attach the attachment? :)

> What remains to be done is to replicate scaled_meter.hpp/scaled_length.hpp for the remaining base units in the <boost/units/base_units/si> directory and to replicate scaled_energy.hpp for all the remaining named SI units in the <boost/units/systems/si> directory.

ok. good. Do you need a test program, like then one below, for all those generated files?

>
> Here's my test program:
>
> #include <iostream>
>
> #include <boost/units/io.hpp>
> #include <boost/units/systems/si/length.hpp>
> #include <boost/units/systems/si/energy.hpp>
>
> #include "scaled_length.hpp"
>
> #include "scaled_energy.hpp"
>
> using namespace boost::units;
> using namespace boost::units::si;
>
> int main()
> {
> std::cout << 1.0*nm << "\t" << 1.5*mJ << std::endl;
>
> quantity<length> q1(1.0*nm);
> quantity<energy> q2(1.5*mJ);
>
> std::cout << q1 << "\t" << q2 << std::endl;
>
> auto q3(1.0*nm);
> auto q4(1.5*mJ);
>
> std::cout << q3 << "\t" << q4 << std::endl;
>
> return 0;
> }
>
> and output :
>
> 1 nm 1.5 mJ
> 1e-09 m 0.0015 m^2 kg s^-2
> 1 nm 1.5 mJ
>
> Note: if you assign these scaled quantities to unscaled quantities, the scaling information will be lost (second output line)...

for now this is not a serious problem. Maybe later when from
functionality we will come to aesthetics of usage... :)

best regards, and thanks a lot for your help! :)

-- 
Janek Kozicki                               http://janek.kozicki.pl/  |

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk