Boost logo

Boost :

Subject: Re: [boost] speed of light from universal_constants Boost.Units
From: Roger Martin (roger_at_[hidden])
Date: 2014-03-10 15:56:40

On 03/10/2014 01:37 PM, Steven Watanabe wrote:
> On 03/10/2014 10:12 AM, Roger Martin wrote:
>> I've tried and tried and just not understanding or can't muddle my way
>> through the boost units(looks powerful though). For a start, just
>> trying to get at the speed of light in
>> boost/units/systems/si/codata/universal_constants.hpp
>> boost::units::si::constants::codata::c
>> boost::units<boost::units::si>::constants::codata::c.value()
>> and massive errors; especially if I try to multiplying with something.
>> I use boost::math::constants::pi<double>() from
>> #include "boost/math/constants/constants.hpp"
>> But the universals allude me; and example? where is my brain stuck?
> I'm not sure. You'll need to give more details.
> (preferable a small /complete/ program that
> doesn't compile)
> The following seems to work for me. (I did run into
> the fact that there's a missing #include<boost/units/quantity.hpp>
> in the constants.)
Ah thank you! I was only using the single header
#include <boost/units/systems/si/codata_constants.hpp>
or with the
#include <boost/units/systems/si.hpp>
before it. And I didn't know about the boost/units/io.hpp when cout'ing
either. Working in a cunit; I'll make a more complete code example with
tests for it and reply again.

I got going with what you showed me but learned the multiplication needs
casting to long double before the math would work/compile. And
division(I'll try more operations).

std::cout<< boost::units::si::constants::codata::c * 2.5l<< std::endl;

failed for me while

std::cout<< boost::units::si::constants::codata::c * 2.5<< std::endl;


> #include<boost/units/quantity.hpp>
> #include<boost/units/systems/si/codata_constants.hpp>
> #include<boost/units/io.hpp>
> #include<iostream>
> int main() {
> std::cout<< boost::units::si::constants::codata::c * 2.5<< std::endl;
> }
> In Christ,
> Steven Watanabe
> _______________________________________________
> Unsubscribe& other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at