I have a bunch of functions that accept two numeric arguments. In the case that the types of these arguments are different I want to figure out what the return type should be. The rule I would like to use is that the largest of the two types should be used for internal computations and the return type.
f(someFloat, someDouble) -> double f(someFloat, someFloat) -> float f(someInt, someFloat) -> float
Is there a way I can do this, perhaps with boost's type_traits?
Take a look at boost::math::tools::promote_args<....>::type defined in boost/math/tools/promotion.hpp: it's an implementation detail so you probably shouldn't rely upon it, but it should give you a good head start. Note that it treats all integer arguments "as if" they were really doubles - so not quite what you asked for - this was done for compatibility with the rules in C99 and the upcoming C++ standard that integer arguments to math functions should be treated as doubles. Should be easy to adapt to what you want though, HTH, John.