Boost logo

Boost :

Subject: Re: [boost] [math] Comeau can't match math::tools::fmod_workaround
From: Mateusz Loskot (mateusz_at_[hidden])
Date: 2009-11-27 15:05:16

John Maddock wrote:
>> Could any one confirm if it is an error indeed?
> These all look to be related, and indicate a genuine issue:
> fabs(long_double_value)
> is returning a double (ie truncated) result :-(
> Can you confirm whether #include <cmath> results in fabs(long double)
> being defined?


I made quick test and it looks std::fabs(long double) is missing:

$ cat long_double_fabs.cpp
#include <cmath>

template <typename T>
T foo(T a, T b) { return a + b; }

int main()
    long double a = -1.23;
    long double b = std::fabs(a); // compiles

    foo( std::fabs(a), b ); // does not compile

$ como --strict --c++ long_double_fabs.cpp
Comeau C/C++ (May 7 2008 12:23:21) for LINUX_INTEL_ELF_Beta
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ noC++0x_extensions

"long_double_fabs.cpp", line 11: error: no instance of function template
          matches the argument list
            argument types are: (double, long double)
      foo( std::fabs(a), b ); // does not compile

1 error detected in the compilation of "long_double_fabs.cpp".

The <cmath> comes from libcomo library:
and it includes <math.h> from GNU C Library.
I generated raw listing (preprocessed, etc.) and it looks that
actual definition of fabs being used comes from GNU C Library and
it truncates input argument to double:

/* Absolute value of X. */
__MATHCALLX (fabs,, (_Mdouble_ __x), (__const__));

It may look like Comeau/libcomo issue, as long double fabs(long double)
should be well defined so the simple template test above is supposed to
work. Am I correct?

Best regards,

Mateusz Loskot,
Charter Member of OSGeo,

Boost list run by bdawes at, gregod at, cpdaniel at, john at