This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: missing declaration for floorl


Fred Hansen wrote:

> The random nubers package in http://www.agner.org/random/ uses function
> floorl. It is present in the cygwin g++ library
> (/lib/gcc/i686-pc-cygwin/3.4.4/libstdc++.a), but is not declared in any of
> the header files (cd /usr/include; grep -rI floorl). If I declare it:
>     long double floorl(long double x);
> then I can call it, link it, and get the correct result.
> 
> Should math.h be augmented with the declaration of floorl?

No.  It's not a mistake that the definition is missing from math.h,
because Cygwin does not provide this function.  libstdc++ is the C++
standard library, and in general it does not implement basic libc
functions like floorl, it relies on the target's C library
implementation for those.  And in fact the floorl that is in libstdc++
is not a real implementation of floorl, it's just a stub:

#ifndef HAVE_FLOORL
long double
floorl(long double x)
{
  return floor((double) x);
}
#endif

The comment at the top of this file (libmath/stubs.c) even says:

/* For targets which do not have support for long double versions,
   we use the crude approximation.  We'll do better later.  */

So it's clear that these functions are only provided as a last resort,
and they aren't even fully correct implementations either since they
just cast away the extra bits.

And even if you added a prototype to math.h for this crude floorl(),
linking would still fail on plain C source using the gcc driver, because
you do not link with libstdc++ unless you use g++.  So it would still be
a broken implementation, but even more confusingly broken since it would
appear to support something that it doesn't.

No, the real problem is not that there are missing prototypes, it's that
actual long double support is missing.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]