Boost logo

Boost :

Subject: Re: [boost] [complex] Feedback and Potential Review Manager
From: Christopher Kormanyos (e_float_at_[hidden])
Date: 2012-05-01 17:41:43


>> But then aren't you removing the optimization >> complex<double> * int that Chris originally proposed ? >> As your int is promoted to a double. Or are you talking >> about non-POD integer-like types ? > No, the promotion is only in calculating the *type of the result*, > if you look at the actual arithmetic in the example, > then the real and imaginary components are directly > multiplied by the arithmetic type. > John. Thanks for the suggestion, John. Matthieu, I checked John's suggestion with both (complex * unsigned int) as well as (signed int * complex) The desired optimization was achieved and numerical integrity was retained with the multiprecision type cpp_dec_float. Matthieu, your code is already looking good! I don't know if you would like to go with this suggestion and I can not pressure you to act on it. I do believe, however, that the suggestion to optimize binary ops with POD will arise in a potential review. In my opinion, this optimization will improve your code. So you might want to look into it. But the decision is yours. I can assist you with the testing of our multiprecision type if this would help your progress. So if you want to look into this, you may want to start with: 1. Binary add, sub, mul, div (complex op POD) and (POD op complex) = 8 template functions 2. Binary equality/inequality (complex op POD) and (POD op complex) = 4 template functions 3. Binary add, sub, mul, div (imaginary op POD) and (POD op imaginary) = 8 template functions The sample below shows both (complex * POD) and (POD * complex) You need to be very careful with stuff like (POD / complex) because the math is a bit more tricky. But you know all that tricky stuff with the norm, etc. Best regards, Chris. /// Returns the value of x times built-in arithmetic type val template <typename Float, typename Arithmetic> inline typename enable_if<is_arithmetic<Arithmetic>, complex<typename boost::math::tools::promote_args<Float, Arithmetic>::type> >::type operator*(const complex<Float>& x, const Arithmetic& val) {   typedef complex<typename boost::math::tools::promote_args<Float, Arithmetic>::type> result_type;   return result_type(x.real() * val, x.imag() * val); } /// Returns the value of built-in arithmetic type val times x template <typename Arithmetic, typename Float> inline typename enable_if<is_arithmetic<Arithmetic>, complex<typename boost::math::tools::promote_args<Float, Arithmetic>::type> >::type operator*(const Arithmetic& val, const complex<Float>& x) {   typedef complex<typename boost::math::tools::promote_args<Float, Arithmetic>::type> result_type;   return result_type(x.real() * val, x.imag() * val); }


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