Boost logo

Boost Users :

Subject: Re: [Boost-users] Problem with user defined Boost Units system
From: Matthias Schabel (boost_at_[hidden])
Date: 2011-12-01 12:56:30


> I am trying to understand the dimensionality of the following two equations.
>
> --- first equation ---
> example::types::radii_t val1 = 5 * example::types::radii;
> example::types::radii_t val2 = 4 * example::types::radii;
>
> example::types::radii_t L1 = 1 / ( val1 - va2 );

va2->val2

This should give you a compile error anyway, since you are trying to assign a length to an inverse length...

> If I was doing the dimensional analysis by hand I would see
>
> 1 / ( radii - radii )
>
> Such that the end type would be
>
> radii^-1
>
> Given that end type here is the second equation:
>
> example::types::radii_t val3 = 5 * example::types::radii;
> example::types::dimensionless_t val4 = 10;
> example::types::dimensionless_t L2 = L1 * val4 * val3;
>
> Doing the dimensional analysis by hand I think I should see:
>
> L2 = radii * (nothing) * radii^-1
> = (nothing) or dimensionless
>
> What Boost Units is reporting is that L2 is actually units in radii_t.

I'm not sure I believe you; the code you pasted is not compilable...did you actually compile anything?

>
> --------- QUESTIONS --------------
>
> Q1: How do you print out the types at compile time?
>
> Q2: How can you confirm you have the correc power for a type? For
> example radii is indeed raised to the -1 power.

Using your earlier header :

#include "types.hpp"

#include <iostream>
#include <boost/units/io.hpp>

using namespace myproject::types;

int main()
{
        radii_t val1(5*radii),
                val2(4*radii);
                        
        //auto L1 = 1/(val1-val2); // compile time error due to failed dimensional consistency
        
        radii_t val3(5*radii);
        
        dimensionless_t val4 = 10;
        dimensionless_t L2(val3*val4/(val1-val2));
        
        std::cout << val1 << std::endl
                  << val2 << std::endl
                  << val3 << std::endl
                  << val4 << std::endl
                  << L2 << std::endl;
        
        return 0;
}

gives

5 r
4 r
5 r
10 dimensionless
50 dimensionless



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net