![]() |
Boost : |
From: John Maddock (john_at_[hidden])
Date: 2008-02-11 04:30:14
Bruno Lalande wrote:
>> Hi,
>>
>> You will find attached to this mail the header file of the pow
>> function, a cpp test file and the documentation in .qbk format.
>> I tried to write docs and tests in accordance to those found in the
>> math library.
>> The files are ready for integration since I placed them respectively
>> into boost/math, libs/math/test and libs/math/doc in my own
>> environment. Let me know if anything has to be changed or added.
>>
>> I passed the tests on :
>> - gcc-2.95 (debian)
>> - gcc-3.3 (debian)
>> - gcc-3.4 (debian)
>> - gcc-4.1 (kubuntu)
>> - icc-10.1 (debian)
>> - msvc-8.0 (XP SP2)
>> - msvc-9.0 (XP SP2)
>>
>> It didn't compile with msvc-6.5. It's not surprising since, if I
>> remember well, this compiler doesn't handle partial template
>> specialization even with SP5. Is this compiler still officially
>> supported by Boost?
>>
>> There is one case for which I don't know what to do : the
>> pow<negative value>(0) case, which obviously crashes since it
>> consists of computing 1/0. Should I check it and throw something, or
>> let the platform's division by 0 behavior (if any) do its effect? I
>> personally think the first approach is better since it ensures an
>> uniform behavior accross platforms.
Can you follow the error handling policies for overflow here:
http://svn.boost.org/svn/boost/trunk/libs/math/doc/sf_and_dist/html/math_toolkit/main_overview/error_handling.html ?
You will need to overload pow like this:
template <int N, class T, class Policy>
typename tools::promote_args<T>::type pow(T, const Policy&)
{
// Actual implementation goes here: uses the specified policy to handle
errors.
}
template <int N, class T>
inline typename tools::promote_args<T>::type pow(T x)
{
return pow<N>(x, policies::policy<>());
}
>> The return type is a double. Now I'm going to study the possibility
>> of
>> having different possible return types.
Using boost::math::tools::promote_args<T>::type to calculate the result type
based on the argument type will work for integer and floating point args:
not sure how this integrates with Boost.Units though.
Keep up the good work! John.
Boost list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk