 # Boost :

Subject: Re: [boost] [units] - learning to use
From: Janek Kozicki (janek_listy_at_[hidden])
Date: 2011-11-25 08:11:16

Thanks a lot for your help,

few questions follow:

> Try D/double(steps).

ok. I'll do this.

> Matthias, I seem to recall that the
> reason we disabled generic multiplication was that it
> was causing ambiguities with user defined types. Do
> you think it would be a good idea to enable arithmetic
> with any built-in arithmetic type?

it would be great.

> Try boost::math?

oh, of course! :)
const double pi = boost::math::constants::pi<double>();

> > (***)
> > it seems strange that I need to take .value() here. The result is
> > dimensionless, why can't it directly convert to complex<double> ?
> > There is a risk that .value() would be expressed in millimeters or
> > angstroms or whatever (maybe depending on dd), and then .value()
> > would return a wrongly scaled number?
> >
>
> This is an idiosyncrasy of overload resolution.
> std::complex::operator+= is a template, so an
> implicit conversion doesn't work. The template
> argument can't be deduced.

OK. So I have to use .value().

The question here: should I expect here some scaling problems? For example:

a = 1nm
b = 1km
c = (a/b).value()

Will c become 1.0, with units scaling being lost, due to directly
taking .value() without taking care of unit scaling. Or would it be
correctly 1e-12 ?

In my problem I am calculating exponent then multiply and
divide by length. In fact the exponent argument is supposed to be
dimensionless also! And as you see I multiply wavenumber by length.
I assume the conversions to ::one are good here :)

Another queestion:

complex<double> i(0,1);
quantity<wavenumber,complex<double> > k=2*pi/lambda;
// [....]
a += (dd*exp(i*k*r)/r).value();

do I really need to define wavenumber k as being complex? After all
it's multiplied by 'i' so it should get converted automatically?

> > quantity<length> wavelength ( 632.8 *nano*meters);
> > quantity<length> wavelength = 632.8 *nano*meters;
> This isn't assignment. It's copy construction and
> requires an implicit conversion which is forbidden.

why it is forbidden?
I think it would be more convenient to allow this.

best regards

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