Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Boost.Units and Boost.Multiprecision
    primarykey
    data
    text
    <p>I am attempting to write a molecular dynamics program, and I thought that Boost.Units was a logical choice for the variables, and I also decided that Boost.Multiprecision offered a better option than <code>double</code> or <code>long double</code> with respect to round off errors. A combination of the two seems fairly straight forward until I attempt to use a constant, then it breaks down.</p> <pre><code>#include &lt;boost/multiprecision/gmp.hpp&gt; #include &lt;boost/units/io.hpp&gt; #include &lt;boost/units/pow.hpp&gt; #include &lt;boost/units/quantity.hpp&gt; #include &lt;boost/units/systems/si.hpp&gt; #include &lt;boost/units/systems/si/codata/physico-chemical_constants.hpp&gt; namespace units = boost::units; namespace si = boost::si; namespace mp = boost::multiprecision; units::quantity&lt;si::mass, mp::mpf_float_50&gt; mass = 1.0 * si::kilogram; units::quantity&lt;si::temperature, mp::mpf_float_50&gt; temperature = 300. * si::kelvin; auto k_B = si::constants::codata::k_B; // Boltzmann constant units::quantity&lt;si::velocity, mp::mpf_float_50&gt; velocity = units::root&lt;2&gt;(temperature * k_B / mass); std::cout &lt;&lt; velocity &lt;&lt; std::endl; </code></pre> <p>The output will be <code>1 M S^-1</code>. If I use <code>long double</code> in lieu of <code>mp::mpf_float_50</code>, then the result is <code>2.87818e-11 m s^-1</code>. I know that the problem likes within the conversion between the constant and the other data because the constant defaults to a <code>double</code>. I have thought about creating my own Boltzmann constant, but I prefer to use the predefined value if possible.</p> <p>My question, therefore, is how do I go about using Boost.Multiprecision when I have predefined constants from Boost.Units? If I must concede to using <code>double</code> or <code>long double</code>, then I will, but I suspect that a way exists to convert or utilize the other on the constants.</p> <p>I am working with Mac OS X 10.7, Xcode 4.6.2, Clang 3.2, Boost 1.53.0 and the C++11 extensions.</p> <p>I appreciate any help that can be offered.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload