
std::complex doesn't seem to allow mixing of types in arithmetic operations. This is quite inconvenient for code that is generic on the base float type. For example: template<typename flt_t> flt_t some_function (std::complex<flt_t> z) { return 2. * z / 4.2 + ... } This will fail to compile when flt_t == float (but succeeds for double). casting every constant in a large computation is really not an acceptable option. Thoughts?

On 07/11/2012 21:27, Neal Becker wrote:
std::complex doesn't seem to allow mixing of types in arithmetic operations. This is quite inconvenient for code that is generic on the base float type.
For example:
template<typename flt_t> flt_t some_function (std::complex<flt_t> z) { return 2. * z / 4.2 + ...
}
This will fail to compile when flt_t == float (but succeeds for double).
casting every constant in a large computation is really not an acceptable option.
Thoughts?
It is a good idea to follow strong typing when writing numerical code, so this limitation is not a very serious problem.

std::complex doesn't seem to allow mixing of types in arithmetic operations. This is quite inconvenient for code that is generic on the base float type.
For example:
template<typename flt_t> flt_t some_function (std::complex<flt_t> z) { return 2. * z / 4.2 + ...
}
This will fail to compile when flt_t == float (but succeeds for double).
casting every constant in a large computation is really not an acceptable option.
Thoughts?
There's a boost::complex in the sandbox waiting for review which I believe fixes that and other issues. John.
participants (3)
-
John Maddock
-
Mathias Gaunard
-
Neal Becker