Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2003-12-13 08:40:03


"Paul A. Bristow" <boost_at_[hidden]> wrote in message
news:AHEJIHEOOOBMJPAGPLIPAEMNEMAA.boost_at_hetp.u-net.com...

[snip]

> Seriously for a moment, one of group who don't use SI (and reluctantly I
must
> admit they can't) are astronomers. A demo using light years (or parsecs?)
would
> also be useful.

//using pqs-100-01 ( a great improvement in speed and accuracy over
pqs-1-00-00)

#include "../pqs.hpp"
using namespace physical_quantities;
double pi(){return 3.141593;}
int main()
{
    p_quantity< //pqs-1-00-01 style
        abstract_pq<3,-2,-1>,
        double,
        -11
>const G(6.7); //gravitational constant 6.7 kg-1.m3.s-2 e-11

    q_length::km const planet_radius(6400); //roughly !
    q_density::kg_div_m3 const planet_density(5464); // roughly!
    q_mass::kg planet_mass = (4.0/3)
    * pi() * power<3>(planet_radius)
    * planet_density;
    std::cout <<"mass of planet is roughly " << planet_mass <<'\n';

    //an object
    q_mass::kg object_mass(1);

    // ...on the planet surface
    q_force::N exerted_force_at_surface
    = (object_mass * planet_mass * G)
    /power<2>(planet_radius);
    std::cout << "force on object at surface is roughly "
    << exerted_force_at_surface <<'\n';

    // ...and a long way away
    q_length::pc object_distance(64e13/3.085678); // pc = 3.085678e16 m
    std::cout <<"force on object at " << object_distance <<" is roughly "
    << q_force::yN((object_mass * planet_mass *
G)/power<2>(object_distance)) <<'\n';
}
/*
output
mass of planet is roughly 5.99983e+024 kg
force on object at surface is roughly 9.81418 N
force on object at 2.0741e+014 [m * 3.08568e+016] is roughly 9.81418e-024 yN
*/

regards
Andy Little


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