delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/08/01/17:18:48

X-Spam-Check-By: sourceware.org
Message-ID: <46B0F897.6168B1BF@dessent.net>
Date: Wed, 01 Aug 2007 14:18:15 -0700
From: Brian Dessent <brian AT dessent DOT net>
X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: missing declaration for floorl
References: <147050 DOT 18700 DOT qm AT web50608 DOT mail DOT re2 DOT yahoo DOT com>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019