By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

Providing a Marhs Library

P: n/a
Folks,

Having spent some considerable effort in sorting out the floating point
code in the I370 port pf GCC, I would now like a floating point library to
go with it. From what I have seen most implementations use "Computer
Approximations" by "P Hart" (hope I got that right) for all the constants.
Unfortunately my local library can't get me a copy. The IEE library in
London does not seem to have a copy. Any other suggestions on a good place
to start? I have looked at the FAQ but that only seems to have extensions.
Any thoughts on a good way to proceed,,,

Dave Wade

Feb 15 '06 #1
Share this Question
Share on Google+
18 Replies


P: n/a
David Wade wrote:
Folks,

Having spent some considerable effort in sorting out the floating point
code in the I370 port pf GCC, I would now like a floating point library to
go with it. From what I have seen most implementations use "Computer
Approximations" by "P Hart" (hope I got that right) for all the constants.
Unfortunately my local library can't get me a copy. The IEE library in
London does not seem to have a copy. Any other suggestions on a good place
to start? I have looked at the FAQ but that only seems to have extensions.
Any thoughts on a good way to proceed,,,


I suggest you look for our very own P.J.Plauger's book:
P.J. Plauger, The Standard C Library, Prentice Hall, 1992, ISBN
0-13-131509-9

It was actually listed in the Bibliography of the FAQ at
http://c-faq.com/sx2/index.html

You might find some of the other references useful.

You might also find having a copy of the C standard to hand useful,
information on where you can get the various versions can be found here
http://clc-wiki.net/wiki/Basics_Of_The_C_Standard
--
Flash Gordon
Living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidlines and intro -
http://clc-wiki.net/wiki/Intro_to_clc
Feb 15 '06 #2

P: n/a
>
I suggest you look for our very own P.J.Plauger's book:
P.J. Plauger, The Standard C Library, Prentice Hall, 1992, ISBN
0-13-131509-9

It was actually listed in the Bibliography of the FAQ at
http://c-faq.com/sx2/index.html

You might find some of the other references useful.

You might also find having a copy of the C standard to hand useful,
information on where you can get the various versions can be found here
http://clc-wiki.net/wiki/Basics_Of_The_C_Standard
--
Both these tell you about using the library, not about implementing it....

Flash Gordon
Living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidlines and intro -
http://clc-wiki.net/wiki/Intro_to_clc

Feb 17 '06 #3

P: n/a
"David Wade" writes:
Having spent some considerable effort in sorting out the floating point
code in the I370 port pf GCC, I would now like a floating point library to
go with it. From what I have seen most implementations use "Computer
Approximations" by "P Hart" (hope I got that right) for all the constants.
Unfortunately my local library can't get me a copy. The IEE library in
London does not seem to have a copy. Any other suggestions on a good place
to start? I have looked at the FAQ but that only seems to have extensions.
Any thoughts on a good way to proceed,,,


No, it's John Hart. Lucky me (I guess), I have a copy. I think AMS55 would
be a decent place to start. It's title is _Handbook of Mathematic
Functions_ and it's hard to imagine a decent technical library that doesn't
have a copy. It's published by the US Dept of Commerce. The book I usually
see referenced is _Numerical Approximations_ (from memory) by Hastings,
which I don't have. Ideally, P.J.Plauger is your best source (after all,
he is up on the current state of the art) and he visits here. But I could
understand if he didn't want to mentor you.
Feb 17 '06 #4

P: n/a
David Wade wrote:
I suggest you look for our very own P.J.Plauger's book:
P.J. Plauger, The Standard C Library, Prentice Hall, 1992, ISBN
0-13-131509-9

It was actually listed in the Bibliography of the FAQ at
http://c-faq.com/sx2/index.html

You might find some of the other references useful.

You might also find having a copy of the C standard to hand useful,
information on where you can get the various versions can be found here
http://clc-wiki.net/wiki/Basics_Of_The_C_Standard
--


Both these tell you about using the library, not about implementing it....


Wrong. To quote from Amazon
http://www.amazon.com/gp/product/013...ebsdprimeiropA
about PJP's book:
| Book Description
| Prentice Hall's most important C programming title in years. A
| companion volume to Kernighan & Ritchie's C PROGRAMMING LANGUAGE. A
| collection of reusable functions (code for building data structures,
| code for performing math functions and scientific calculations, etc.)
| which will save C programmers time and money especially when working
| on large programming projects. The C Library is part of the ANSI
| (American National Standard Institute) for the C Language. This new
| book contains the complete code for the library...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It is also very useful to have the definition of what you are trying to
implement, hence my suggestion of the standard.
Flash Gordon
Living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidlines and intro -
http://clc-wiki.net/wiki/Intro_to_clc


Please snip peoples sigs unless you are commenting on them.
--
Flash Gordon
Living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidlines and intro -
http://clc-wiki.net/wiki/Intro_to_clc
Feb 17 '06 #5

P: n/a
On 2006-02-15, David Wade <g8***@yahoo.com> wrote:
Folks,

Having spent some considerable effort in sorting out the floating point
code in the I370 port pf GCC, I would now like a floating point library to
go with it. From what I have seen most implementations use "Computer
Approximations" by "P Hart" (hope I got that right) for all the constants.
Unfortunately my local library can't get me a copy. The IEE library in
London does not seem to have a copy. Any other suggestions on a good place
to start? I have looked at the FAQ but that only seems to have extensions.
Any thoughts on a good way to proceed,,,

Dave Wade


There is an open-source (BSD-ish, but with less license verbage) math
library [including all functions declared in math.h] that originated
with SunPro - It does require [as far as I can tell] IEEE floating
point, and the compiler has to handle primitives such as division,
multiplication, and so on.

No idea where to find it, except for of course my own system's
/usr/src/lib/msun/src

Or there's always glibc.
Feb 17 '06 #6

P: n/a

"Jordan Abel" <ra*******@gmail.com> wrote in message
news:sl**********************@random.yi.org...
On 2006-02-15, David Wade <g8***@yahoo.com> wrote:
Folks,

Having spent some considerable effort in sorting out the floating point
code in the I370 port pf GCC, I would now like a floating point library to go with it. From what I have seen most implementations use "Computer
Approximations" by "P Hart" (hope I got that right) for all the constants. Unfortunately my local library can't get me a copy. The IEE library in
London does not seem to have a copy. Any other suggestions on a good place to start? I have looked at the FAQ but that only seems to have extensions. Any thoughts on a good way to proceed,,,

Dave Wade
There is an open-source (BSD-ish, but with less license verbage) math
library [including all functions declared in math.h] that originated
with SunPro - It does require [as far as I can tell] IEEE floating
point, and the compiler has to handle primitives such as division,
multiplication, and so on.


Thats a major problem as I370 does not have IEEE float....
No idea where to find it, except for of course my own system's
/usr/src/lib/msun/src

Or there's always glibc.

Feb 18 '06 #7

P: n/a

"Flash Gordon" <sp**@flash-gordon.me.uk> wrote in message
news:3o************@news.flash-gordon.me.uk...
David Wade wrote:
I suggest you look for our very own P.J.Plauger's book:
P.J. Plauger, The Standard C Library, Prentice Hall, 1992, ISBN
0-13-131509-9

It was actually listed in the Bibliography of the FAQ at
http://c-faq.com/sx2/index.html

You might find some of the other references useful.

You might also find having a copy of the C standard to hand useful,
information on where you can get the various versions can be found here
http://clc-wiki.net/wiki/Basics_Of_The_C_Standard
--
Both these tell you about using the library, not about implementing it....
Wrong. To quote from Amazon
http://www.amazon.com/gp/product/013...ebsdprimeiropA about PJP's book:
| Book Description
| Prentice Hall's most important C programming title in years. A
| companion volume to Kernighan & Ritchie's C PROGRAMMING LANGUAGE. A
| collection of reusable functions (code for building data structures,
| code for performing math functions and scientific calculations, etc.)
| which will save C programmers time and money especially when working
| on large programming projects. The C Library is part of the ANSI
| (American National Standard Institute) for the C Language. This new
| book contains the complete code for the library...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Arghhhh! How did I miss that. I can't even say that the description in
amazon.co.uk is different.
That looks a really usefull starting point...

It is also very useful to have the definition of what you are trying to
implement, hence my suggestion of the standard.


I agree, but the standard is pretty brief on the maths functions. Most only
warrent a one liner. However at it does have the range values that are
valid...
Flash Gordon


Thanks,
Dave
Feb 18 '06 #8

P: n/a
>"osmium" <r1********@comcast.net> wrote in message
news:45************@individual.net...
"David Wade" writes:
Having spent some considerable effort in sorting out the floating point
code in the I370 port pf GCC, I would now like a floating point library to go with it. From what I have seen most implementations use "Computer
Approximations" by "P Hart" (hope I got that right) for all the constants. Unfortunately my local library can't get me a copy. The IEE library in
London does not seem to have a copy. Any other suggestions on a good place to start? I have looked at the FAQ but that only seems to have extensions. Any thoughts on a good way to proceed,,,
No, it's John Hart. Lucky me (I guess), I have a copy. I think AMS55

would be a decent place to start. It's title is _Handbook of Mathematic
Functions_ and it's hard to imagine a decent technical library that doesn't have a copy. It's published by the US Dept of Commerce.
Oddly I can't see this in the IEE library...
The book I usually
see referenced is _Numerical Approximations_ (from memory) by Hastings,
Do you mean "Approximations for digital computers" That is in the IEE
library...
which I don't have. Ideally, P.J.Plauger is your best source (after all,
he is up on the current state of the art) and he visits here. But I could
understand if he didn't want to mentor you.


Any way some stuff to go on here....
Feb 18 '06 #9

P: n/a
"David Wade" wrote:

I think AMS55

would
be a decent place to start. It's title is _Handbook of Mathematic
Functions_ and it's hard to imagine a decent technical library that

doesn't
have a copy. It's published by the US Dept of Commerce.


Oddly I can't see this in the IEE library...


It's on the net, too.

http://www.convertit.com/Go/ConvertI...ence/AMS55.ASP

Typing a number into <page> works. It's a scanned copy.
The book I usually
see referenced is _Numerical Approximations_ (from memory) by Hastings,


Do you mean "Approximations for digital computers" That is in the IEE
library...


Yes, that's the one.

Feb 18 '06 #10

P: n/a
>
It's on the net, too.

http://www.convertit.com/Go/ConvertI...ence/AMS55.ASP

Typing a number into <page> works. It's a scanned copy.


That looks more usefull. Thanks for that...
The book I usually
see referenced is _Numerical Approximations_ (from memory) by Hastings,


Do you mean "Approximations for digital computers" That is in the IEE
library...


Yes, that's the one.

Feb 20 '06 #11

P: n/a

"David Wade" <g8***@yahoo.com> wrote in message
news:T4******************************@eclipse.net. uk...
Folks,

Having spent some considerable effort in sorting out the floating point
code in the I370 port pf GCC, I would now like a floating point library to
go with it. From what I have seen most implementations use "Computer
Approximations" by "P Hart" (hope I got that right) for all the constants.
Unfortunately my local library can't get me a copy. The IEE library in
London does not seem to have a copy. Any other suggestions on a good place
to start? I have looked at the FAQ but that only seems to have extensions.
Any thoughts on a good way to proceed,,,

Dave Wade


Have you looked at Sun Microsystems freely distributable math library,
fdlibm?

You could also use the math library SLATEC. You'll need to convert them
from Fortran to C using F2C.

Rod Pemberton

Netlib's main pages:
http://netlib.bell-labs.com/netlib/master/readme.html
http://netlib.bell-labs.com/netlib/master/index.html

Direct links to fdlibm,f2c,slatec:
http://netlib.bell-labs.com/netlib/fdlibm/index.html
http://netlib.bell-labs.com/netlib/f2c/index.html
http://netlib.bell-labs.com/netlib/slatec/index.html

They might also be available here:
http://www.netlib.org/slatec
http://www.netlib.org/fdlibm
http://www.netlib.org/f2c


Feb 20 '06 #12

P: n/a
Rod Pemberton wrote:
"David Wade" <g8***@yahoo.com> wrote in message
news:T4******************************@eclipse.net. uk...
Folks,

Having spent some considerable effort in sorting out the floating point
code in the I370 port pf GCC, I would now like a floating point library to
go with it. From what I have seen most implementations use "Computer
Approximations" by "P Hart" (hope I got that right) for all the constants.
Unfortunately my local library can't get me a copy. The IEE library in
London does not seem to have a copy. Any other suggestions on a good place
to start? I have looked at the FAQ but that only seems to have extensions.
Any thoughts on a good way to proceed,,,

Dave Wade


Have you looked at Sun Microsystems freely distributable math library,
fdlibm?

You could also use the math library SLATEC. You'll need to convert them
from Fortran to C using F2C.

Rod Pemberton

Netlib's main pages:
http://netlib.bell-labs.com/netlib/master/readme.html
http://netlib.bell-labs.com/netlib/master/index.html

Direct links to fdlibm,f2c,slatec:
http://netlib.bell-labs.com/netlib/fdlibm/index.html
http://netlib.bell-labs.com/netlib/f2c/index.html
http://netlib.bell-labs.com/netlib/slatec/index.html

They might also be available here:
http://www.netlib.org/slatec
http://www.netlib.org/fdlibm
http://www.netlib.org/f2c


Rod,

The only problem with fdlibm is that some funcions (especially the LOG
functions) only work properley with binary float, whereas IBM float is
Hex floating point. (that is the exponent is a power of 16, not of
two). This means that code that multiplys or divides by two by
manipulating the exponent directly does not work. I guess its fixable
though, and the code does have pretty good explainations of what is
happening, and good examples of suitable constants for use in the
polynomial approximations, which are too a greater accuracy than those
in AMS55.

Dave.

P.S. SALTEC appears to assume you already have basic trig :-(

Feb 21 '06 #13

P: n/a
Dave wrote:
The only problem with fdlibm is that some funcions (especially the LOG
functions) only work properley with binary float, whereas IBM float is
Hex floating point. (that is the exponent is a power of 16, not of
two). This means that code that multiplys or divides by two by
manipulating the exponent directly does not work. I guess its fixable
though, and the code does have pretty good explainations of what is
happening, and good examples of suitable constants for use in the
polynomial approximations, which are too a greater accuracy than those
in AMS55.


Sometimes I write math functions, when I have nothing else to do.

/* BEGIN constants.c output */

sq_rt(2) is 1.414214
l_og(2) is 0.693147
e_xp(1) is 2.718282
pi is 3.141593

sq_rt(2) * sq_rt(2) - 2.0 is -4.440892e-016
sqrt(2) * sqrt(2) - 2.0 is 4.440892e-016

pow(e_xp(1), l_og(2)) - 2.0 is -2.220446e-016
pow(exp(1), log(2)) - 2.0 is -2.220446e-016

3.141592653589793238462643383279502884197169399375 1 - fs_pi()
is 0.000000e+000

/* END constants.c output */

/* BEGIN constants.c */

#include <stdio.h>
#include <float.h>
#include <errno.h>
#include <math.h>

double sq_rt(double x);
double l_og(double x);
double e_xp(double x);
double fs_pi(void);

int main(void)
{
puts("\n/* BEGIN constants.c output */\n");
printf("sq_rt(2) is %f\n", sq_rt(2));
printf(" l_og(2) is %f\n", l_og(2));
printf(" e_xp(1) is %f\n", e_xp(1));
printf(" pi is %f\n\n", fs_pi( ));

printf("sq_rt(2) * sq_rt(2) - 2.0 is %e\n",
sq_rt(2) * sq_rt(2) - 2.0);
printf(" sqrt(2) * sqrt(2) - 2.0 is %e\n\n",
sqrt(2) * sqrt(2) - 2.0);
printf("pow(e_xp(1), l_og(2)) - 2.0 is %e\n",
pow(e_xp(1), l_og(2)) - 2.0);
printf(" pow(exp(1), log(2)) - 2.0 is %e\n\n",
pow(exp(1), log(2)) - 2.0);
printf("3.1415926535897932384626433832795028841971 693993751"
" - fs_pi()\nis %e\n",
3.141592653589793238462643383279502884197169399375 1
- fs_pi());
puts("\n/* END constants.c output */");
return 0;
}

double sq_rt(double x)
{
int n;
double a, b;

if (DBL_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) {
errno = EDOM;
x = HUGE_VAL;
}
}
return x;
}

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

if (DBL_MAX >= x && x > 0) {
if (1 > A) {
A = sq_rt(2);
B = A / 2;
C = l_og(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 = DBL_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 {
errno = x != 0 ? EDOM : ERANGE;
x = -HUGE_VAL;
}
return x;
}

double e_xp(double x)
{
unsigned n, square;
double b, e;
static double x_max;

if (1 > x_max) {
x_max = l_og(DBL_MAX);
}
if (x_max >= x && x >= -x_max) {
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 > DBL_EPSILON / 4);
while (square-- != 0) {
e *= e;
}
} else {
errno = x > DBL_MAX || -DBL_MAX > x ? EDOM : ERANGE;
e = 0 > x ? 0 : HUGE_VAL;
}
return e;
}

double fs_pi(void)
{
unsigned n;
double p, a, b;

p = 0;
n = 1;
a = 3;
do {
a /= 9;
b = a / n;
n += 2;
a /= 9;
b -= a / n;
n += 2;
p += b;
} while (b > DBL_EPSILON / 4);
n = 1;
a = 2;
do {
a /= 4;
b = a / n;
n += 2;
a /= 4;
b -= a / n;
n += 2;
p += b;
} while (b > DBL_EPSILON / 2);
return 4 * p;
}

/* END constants.c */

--
pete
Feb 21 '06 #14

P: n/a

"pete" <pf*****@mindspring.com> wrote in message
news:43***********@mindspring.com...
Dave wrote:
The only problem with fdlibm is that some funcions (especially the LOG
functions) only work properley with binary float, whereas IBM float is
Hex floating point. (that is the exponent is a power of 16, not of
two). This means that code that multiplys or divides by two by
manipulating the exponent directly does not work. I guess its fixable
though, and the code does have pretty good explainations of what is
happening, and good examples of suitable constants for use in the
polynomial approximations, which are too a greater accuracy than those
in AMS55.


Sometimes I write math functions, when I have nothing else to do.

<snip>

Pete,

Those functions are nice. Martin Baute has said he could use some help
with math functions. He's writing a Public Domain C library hosted on
Sourceforge:

http://sourceforge.net/projects/pdclib/

Rod Pemberton
Feb 21 '06 #15

P: n/a
Rod Pemberton wrote:

"pete" <pf*****@mindspring.com> wrote in message
news:43***********@mindspring.com...
Dave wrote:
The only problem with fdlibm is that some funcions (especially the LOG
functions) only work properley with binary float, whereas IBM float is
Hex floating point. (that is the exponent is a power of 16, not of
two). This means that code that multiplys or divides by two by
manipulating the exponent directly does not work. I guess its fixable
though, and the code does have pretty good explainations of what is
happening, and good examples of suitable constants for use in the
polynomial approximations, which are too a greater accuracy than those
in AMS55.
Sometimes I write math functions, when I have nothing else to do.

<snip>

Pete,

Those functions are nice.


I'm glad you like them.
Most of them are just transcriptions of some Taylor
and Maclaurin series from my math book.
Martin Baute has said he could use some help
with math functions. He's writing a Public Domain C library hosted on
Sourceforge:

http://sourceforge.net/projects/pdclib/


I just downloaded their standard library.
I'll take a look at it.

--
pete
Feb 21 '06 #16

P: n/a

"Rod Pemberton" <do*********@sorry.bitbucket.cmm> wrote in message
news:dt**********@news1.greatnowhere.com...

"pete" <pf*****@mindspring.com> wrote in message
news:43***********@mindspring.com...
Dave wrote:
The only problem with fdlibm is that some funcions (especially the LOG functions) only work properley with binary float, whereas IBM float is
Hex floating point. (that is the exponent is a power of 16, not of
two). This means that code that multiplys or divides by two by
manipulating the exponent directly does not work. I guess its fixable
though, and the code does have pretty good explainations of what is
happening, and good examples of suitable constants for use in the
polynomial approximations, which are too a greater accuracy than those
in AMS55.
Sometimes I write math functions, when I have nothing else to do.

<snip>

Pete,

Those functions are nice. Martin Baute has said he could use some help
with math functions. He's writing a Public Domain C library hosted on
Sourceforge:


They will work, but they are a bit on the slow side when running on an
emulated mainframe...
I have been using the library from

http://sourceforge.net/projects/pdos

Which again is missing any maths...
http://sourceforge.net/projects/pdclib/

Rod Pemberton

Feb 21 '06 #17

P: n/a
David Wade wrote:

"Rod Pemberton" <do*********@sorry.bitbucket.cmm> wrote in message
news:dt**********@news1.greatnowhere.com...

"pete" <pf*****@mindspring.com> wrote in message
news:43***********@mindspring.com...
Sometimes I write math functions, when I have nothing else to do.

<snip>

Pete,

Those functions are nice.
Martin Baute has said he could use some help
with math functions.
He's writing a Public Domain C library hosted on
Sourceforge:


They will work, but they are a bit on the slow side when running on an
emulated mainframe...


I'm not quite sure why I wrote them.
But if you remove all the statements with errno,
and change all the instances of HUGE_VAL to DBL_MAX,
then you have portable freestanding code.

--
pete
Feb 23 '06 #18

P: n/a
In article <11**********************@g14g2000cwa.googlegroups .com> "Dave" <g8***@yahoo.com> writes:
....
The only problem with fdlibm is that some funcions (especially the LOG
functions) only work properley with binary float, whereas IBM float is
Hex floating point. (that is the exponent is a power of 16, not of
two).


You should look at W.J. Cody and W. Waite. It goes in full detail over
the implementation of the elementary functions, and it is not binary
biased. (Although I do not like their implementation of some of the
functions.)

They also give programs (in Fortran) that test the functions.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Feb 23 '06 #19

This discussion thread is closed

Replies have been disabled for this discussion.