473,738 Members | 8,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

long double versions of functions in gcc under Cygwin

Greetings, all,

I am trying to port a little bit of math code to gcc, that in the
original version used the long double version of several functions (in
particular, atanl, fabsl, and expl).

I get a complie-time "unidentifi ed reference" error to the expl()
calls, but gcc seems to digest atanl and fabsl just fine. Changing expl
to exp cures the compile time problem, but I get at best double
precision in the final results. I am assuming that the use of exp() vs.
expl() is the weak link.

The GCC documentation seems to imply that expl() is supported, but I
have no idea where to find it or how to link it in properly. For that
matter, I can't seem to find prototypes in math.h for fabsl or atanl,
and they don't make gcc cough at all.

I hope this tenderfoot can find some direction, or I may resort to
singing the praises of the egregiously un-portable lcc-win32 with its
impressive 100+ digit precision qfloat library ;)

cheers,

Les

p.s. I am trying to keep this simple, so if there is a solution within
the main gcc offerings without me having to turn to the GSL, I would
like to try that first.

Aug 7 '06 #1
52 5984
"lcw1964" <le***********@ alumni.uwo.cawr ites:
I am trying to port a little bit of math code to gcc, that in the
original version used the long double version of several functions (in
particular, atanl, fabsl, and expl).

I get a complie-time "unidentifi ed reference" error to the expl()
calls, but gcc seems to digest atanl and fabsl just fine. Changing expl
to exp cures the compile time problem, but I get at best double
precision in the final results. I am assuming that the use of exp() vs.
expl() is the weak link.

The GCC documentation seems to imply that expl() is supported, but I
have no idea where to find it or how to link it in properly. For that
matter, I can't seem to find prototypes in math.h for fabsl or atanl,
and they don't make gcc cough at all.

I hope this tenderfoot can find some direction, or I may resort to
singing the praises of the egregiously un-portable lcc-win32 with its
impressive 100+ digit precision qfloat library ;)

cheers,

Les

p.s. I am trying to keep this simple, so if there is a solution within
the main gcc offerings without me having to turn to the GSL, I would
like to try that first.
gcc is a compiler, not a complete C implementation. (Actually gcc is
a collection of compilers, but for our purposes here we can consider
only the C compiler.) The math functions are implemented by the
runtime library, not by the compiler.

In some implementations , the compiler and the runtime library are
provided together. gcc, however, generally uses whatever runtime
library is provided by the underlying operating system. On some
systems, the C runtime library happens to be one that, like gcc, is
also provided by the GNU project. I suspect you're using a system
where that isn't the case.

I suggest you ask in a newsgroup that deals with your operating system
(probably MS Windows given your mention of lcc-win32 as an
alternative).

(I don't know whether lcc-win32 provides its own C runtime library;
check the web site or ask in comp.compilers. lcc if you want more
information.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 7 '06 #2
Keith Thompson wrote:
>
In some implementations , the compiler and the runtime library are
provided together. gcc, however, generally uses whatever runtime
library is provided by the underlying operating system. On some
systems, the C runtime library happens to be one that, like gcc, is
also provided by the GNU project. I suspect you're using a system
where that isn't the case.

I think you are right, and I was afraid it had something to do with
that.

I am learning quickly that if I wish to make the most out of higher
precision math programming, it behooves me to expand my horizons and
develop some facility with a high or even arbitrary precision package,
though I must admit that some of the source code I have contemplated
looks daunting indeed for this beginner.

In the meantime, lcc-win32 seems a reasonable, though admittedly
non-portable option. Messr. Navia's implementation of the Cephes qfloat
library seems pretty robust and at least in my barely ept hands
produces prodigious results with surprising little change to code. For
example, the very code that I am having trouble getting full long
double results with gcc/Cygwin with lcc-win32/qfloat routinely gives
102-105 digit accuracy most of the time, and at least 100 digits all of
the time. It is simply a matter of including qfloat.h, change various
commands to their qfloat equivalents (atoq, expq, atanq, etc.),
appending a q to floating point constants, and properly formatting the
output strings for printf or whatever. For my limited personal
purposes, it is about the best option I have hit upon so far, though I
do admit that cross-platform and cross-compiler compatibility would be
much more vital if my interests were less parochial.

Thanks for the feedback, though I must admit it leaves me with 3.1 gigs
of Cygwin on my hard drive that I don't know quite what to do with ;)

Les

Aug 8 '06 #3
"lcw1964" <le***********@ alumni.uwo.cawr ote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
Greetings, all,

I am trying to port a little bit of math code to gcc, that in the
original version used the long double version of several functions (in
particular, atanl, fabsl, and expl).

I get a complie-time "unidentifi ed reference" error to the expl()
calls, but gcc seems to digest atanl and fabsl just fine. Changing expl
to exp cures the compile time problem, but I get at best double
precision in the final results. I am assuming that the use of exp() vs.
expl() is the weak link.

The GCC documentation seems to imply that expl() is supported, but I
have no idea where to find it or how to link it in properly. For that
matter, I can't seem to find prototypes in math.h for fabsl or atanl,
and they don't make gcc cough at all.

I hope this tenderfoot can find some direction, or I may resort to
singing the praises of the egregiously un-portable lcc-win32 with its
impressive 100+ digit precision qfloat library ;)
The qfloat library is by S. Moshier. You can find qfloat along with the
Cephes collection (which has tons of long double math functions) here:

http://www.moshier.net/#Cephes
cheers,

Les

p.s. I am trying to keep this simple, so if there is a solution within
the main gcc offerings without me having to turn to the GSL, I would
like to try that first.

Aug 8 '06 #4

Dann Corbit wrote:
>
The qfloat library is by S. Moshier. You can find qfloat along with the
Cephes collection (which has tons of long double math functions) here:

http://www.moshier.net/#Cephes
Thank you! I should have given Mr. Moshier proper credit. I am also
aware of the link you referred me to, my right now porting those
libraries to GCC is a little beyond my skill set, so being able to
access the qfloat functionality thru Mr. Navia's lcc-win32 "wrapper" is
a good start.

Les

Aug 8 '06 #5
"lcw1964" <le***********@ alumni.uwo.cawr ote in message
news:11******** **************@ n13g2000cwa.goo glegroups.com.. .
>
Dann Corbit wrote:
>>
The qfloat library is by S. Moshier. You can find qfloat along with the
Cephes collection (which has tons of long double math functions) here:

http://www.moshier.net/#Cephes

Thank you! I should have given Mr. Moshier proper credit. I am also
aware of the link you referred me to, my right now porting those
libraries to GCC is a little beyond my skill set, so being able to
access the qfloat functionality thru Mr. Navia's lcc-win32 "wrapper" is
a good start.
You don't have to know anything. They come with their own makefiles.

At most, you will have to know what kind of machine you are compiling on (if
it is not a 32 bit platform or has odd endianness or something).

The standard makefile will probably fit your situation.

Just expand this archive:
http://www.moshier.net/qlib.zip
and type "make"

The Cephes functions are even the default math functions used in some linux
distributions (IIRC).
Aug 8 '06 #6
On Mon, 7 Aug 2006 21:11:08 -0700, "Dann Corbit" <dc*****@connx. com>
wrote:
>"lcw1964" <le***********@ alumni.uwo.cawr ote in message
news:11******* *************** @n13g2000cwa.go oglegroups.com. ..
>>
Dann Corbit wrote:
>>>
The qfloat library is by S. Moshier. You can find qfloat along with the
Cephes collection (which has tons of long double math functions) here:

http://www.moshier.net/#Cephes

Thank you! I should have given Mr. Moshier proper credit. I am also
aware of the link you referred me to, my right now porting those
libraries to GCC is a little beyond my skill set, so being able to
access the qfloat functionality thru Mr. Navia's lcc-win32 "wrapper" is
a good start.

You don't have to know anything. They come with their own makefiles.

At most, you will have to know what kind of machine you are compiling on (if
it is not a 32 bit platform or has odd endianness or something).

The standard makefile will probably fit your situation.

Just expand this archive:
http://www.moshier.net/qlib.zip
and type "make"

The Cephes functions are even the default math functions used in some linux
distribution s (IIRC).
There are 477 usages of "goto" in this source. That gives me a queasy
feeling.

One part of me sees me sitting through a code review and vehemently
rebuking this code after coming across about the 5th goto statement.
The other part of me sees me reviewing the black box test results that
passed and not caring about how this was coded, as long as it was
coded in Standard C. Oh the dichotomy.

--
Jay

Aug 8 '06 #7
jaysome a écrit :
There are 477 usages of "goto" in this source. That gives me a queasy
feeling.
I rewrote all the basic functions in 386 and AMD64 assembly.
The speed gain is considerable, and the gotos are even worst:

Who hasn't written a

jmp label

in assembly?

Seriously, the code is well written, and if you look at the
dates in there you will se code from eighties. And it still runs,
twenty years later.

I would like to see what code you have written in 20 years, even
if it doesn't use gotos.

Stephen Moshier has written a very good package.

One part of me sees me sitting through a code review and vehemently
rebuking this code after coming across about the 5th goto statement.
This is just dogmatic. gotos arre part of C. And they are used in
the Cephes library in a reasonable and very clear way.
The other part of me sees me reviewing the black box test results that
passed and not caring about how this was coded, as long as it was
coded in Standard C. Oh the dichotomy.
Aug 8 '06 #8
lcw1964 wrote:
expl()
#include <float.h>

long double fs_expl(long double x);
long double fs_logl(long double x);
long double fs_sqrtl(long double x);

long double fs_expl(long double x)
{
long unsigned n, square;
long double b, e;
static long double x_max, x_min;

if (1 x_max) {
x_max = fs_logl(LDBL_MA X);
x_min = fs_logl(LDBL_MI N);
}
if (x_max >= x && x >= x_min) {
for (square = 0; x 1; x /= 2) {
++square;
}
while (-1 x) {
++square;
x /= 2;
}
e = b = n = 1;
do {
b /= n++;
b *= x;
e += b;
b /= n++;
b *= x;
e += b;
} while (b LDBL_EPSILON / 4);
while (square-- != 0) {
e *= e;
}
} else {
e = x 0 ? LDBL_MAX : 0;
}
return e;
}

long double fs_logl(long double x)
{
long int n;
long double a, b, c, epsilon;
static long double A, B, C;

if (LDBL_MAX >= x && x 0) {
if (1 A) {
A = fs_sqrtl(2);
B = A / 2;
C = fs_logl(A);
}
for (n = 0; x A; x /= 2) {
++n;
}
while (B x) {
--n;
x *= 2;
}
a = (x - 1) / (x + 1);
x = C * n + a;
c = a * a;
n = 1;
epsilon = LDBL_EPSILON * x;
if (0 a) {
if (epsilon 0) {
epsilon = -epsilon;
}
do {
n += 2;
a *= c;
b = a / n;
x += b;
} while (epsilon b);
} else {
if (0 epsilon) {
epsilon = -epsilon;
}
do {
n += 2;
a *= c;
b = a / n;
x += b;
} while (b epsilon);
}
x *= 2;
} else {
x = -LDBL_MAX;
}
return x;
}

long double fs_sqrtl(long double x)
{
long int n;
long double a, b;

if (LDBL_MAX >= x && x 0) {
for (n = 0; x 2; x /= 4) {
++n;
}
while (0.5 x) {
--n;
x *= 4;
}
a = x;
b = (1 + x) / 2;
do {
x = b;
b = (a / x + x) / 2;
} while (x b);
while (n 0) {
x *= 2;
--n;
}
while (0 n) {
x /= 2;
++n;
}
} else {
if (x != 0) {
x = LDBL_MAX;
}
}
return x;
}

--
pete
Aug 8 '06 #9
pete a écrit :
lcw1964 wrote:

>>expl()


#include <float.h>

long double fs_expl(long double x);
long double fs_logl(long double x);
long double fs_sqrtl(long double x);

long double fs_expl(long double x)
{
long unsigned n, square;
long double b, e;
static long double x_max, x_min;

if (1 x_max) {
x_max = fs_logl(LDBL_MA X);
x_min = fs_logl(LDBL_MI N);
}
if (x_max >= x && x >= x_min) {
for (square = 0; x 1; x /= 2) {
++square;
}
while (-1 x) {
++square;
x /= 2;
}
e = b = n = 1;
do {
b /= n++;
b *= x;
e += b;
b /= n++;
b *= x;
e += b;
} while (b LDBL_EPSILON / 4);
while (square-- != 0) {
e *= e;
}
} else {
e = x 0 ? LDBL_MAX : 0;
}
return e;
}

long double fs_logl(long double x)
{
long int n;
long double a, b, c, epsilon;
static long double A, B, C;

if (LDBL_MAX >= x && x 0) {
if (1 A) {
A = fs_sqrtl(2);
B = A / 2;
C = fs_logl(A);
}
for (n = 0; x A; x /= 2) {
++n;
}
while (B x) {
--n;
x *= 2;
}
a = (x - 1) / (x + 1);
x = C * n + a;
c = a * a;
n = 1;
epsilon = LDBL_EPSILON * x;
if (0 a) {
if (epsilon 0) {
epsilon = -epsilon;
}
do {
n += 2;
a *= c;
b = a / n;
x += b;
} while (epsilon b);
} else {
if (0 epsilon) {
epsilon = -epsilon;
}
do {
n += 2;
a *= c;
b = a / n;
x += b;
} while (b epsilon);
}
x *= 2;
} else {
x = -LDBL_MAX;
}
return x;
}

long double fs_sqrtl(long double x)
{
long int n;
long double a, b;

if (LDBL_MAX >= x && x 0) {
for (n = 0; x 2; x /= 4) {
++n;
}
while (0.5 x) {
--n;
x *= 4;
}
a = x;
b = (1 + x) / 2;
do {
x = b;
b = (a / x + x) / 2;
} while (x b);
while (n 0) {
x *= 2;
--n;
}
while (0 n) {
x /= 2;
++n;
}
} else {
if (x != 0) {
x = LDBL_MAX;
}
}
return x;
}
I find this code well DOCUMENTED isn't it?

The source of the code (who wrote it originally), the algorithms
used are well explained, the places in the code where you have to
watch for accuracy are pointed out, a nice package.

fs_sqrt is approximately 20 times slower
than the library function.

Aug 8 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
22627
by: f | last post by:
I have this double sum, a, b, c; sum = a + b + c; printf("%.20f = %.20f, %.20f, %.20f", sum, a, b, c); I found that the debug version and release version of the same code give me different result. I am using VC++ 6.0. In debug version, the print out is:
13
9024
by: Ryan Lee | last post by:
How to use math functions of type long double in gcc? I used powl and expl in my source code (and included math.h) but I got "undefined reference to `_powl'" when I tried to compile it with: gcc -o 1_1prog 1_1prog.c -lm I also tried "-ansi" and "-std=c99" but still got the same message. Does anyone have any idea? Thanks a lot!
7
3361
by: Chris Croughton | last post by:
Could someone who has access to the C89 specification please confirm whether the type long double existed in that spec.? The only copy I have is from the early draft stages, and it wasn't in that (tatty paper copy). I have tests in some of my source code from the early 90s to detect whether long double was present (including float.h and testing for some of the macros), but that may have been for non-conforming compilers. (gcc -std=c89...
67
9907
by: lcw1964 | last post by:
This may be in the category of bush-league rudimentary, but I am quite perplexed on this and diligent Googling has not provided me with a clear straight answer--perhaps I don't know how to ask the quesion. I have begun to familiarize myself here with the gcc compiler in a win32 environment, in the form of MinGW using both Dev C++ and MSYS as interfaces. I have recompiled some old math code that uses long double types throughout and...
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6751
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.