All Forums |
Register |
Login |
Search |
Subscriptions |
My Profile |
Inbox |
Tool Warehouse |
FAQs |
Resources |
Help |
Member List |
Address Book |
Logout |
|
|
trouble in libmath?
|
Logged in as: Guest |
Users viewing this topic: none |
|
Login  |
|
|
trouble in libmath? - Aug. 24, '06, 2:51:17 PM
|
|
|
bardanjam
Posts: 1
Joined: Aug. 20, '06,
Status: offline
|
good afternoon (or morning or evening ...)
This is my first experience with SFU and Interix. I'm running SFU 3.5 on WinXP Pro SP2, with all current patches and updates, with the SFU and GNU SDKs installed. I've also installed the Toolworks 2.3 CD, as well as Visual C++ Express 2005.
I've found what seems to be a bug in the math library ... the function for computing a single-precision natural logarithm (logf) is returning very incorrect data. I've determined that the problem lies *only* with the logf function ... it's double-precision counterpart, log, works just fine. Base-10 logarithms, log10f and log10, also work fine - it's just logf that has the problem.
Has anyone else encountered this problem? Is it possibly related to any compiler or linker options I'm using?
My compile command:
gcc -o logtest -D_ALL_SOURCE logtest.c -lm
BTW, adding "-I/usr/local/include -L/usr/local/lib" does not solve the problem.
My test program:
#include <stdio.h>
#include <math.h>
int main() {
float f, f_log, f_log10;
double d, d_log, d_log10;
int i;
printf("x logf(e^x) log(e^x) log10f(10^x) log10(10^x)\n");
printf("---------------------------------------------------\n");
for (i=-5; i<=5; i++) {
f = powf(M_E, i);
d = pow (M_E, i);
f_log = logf(f);
d_log = log(d);
f = powf(10.0, i);
d = pow(10.0, i);
f_log10 = log10f(f);
d_log10 = log10(d);
printf("%2d % 9.5f % 8.5f % 12.5f % 11.5f\n", i, f_log, d_log, f_log10, d_log10);
}
return 0;
}
And, my output:
x logf(e^x) log(e^x) log10f(10^x) log10(10^x)
---------------------------------------------------
-5 0.00674 -5.00000 -5.00000 -5.00000
-4 0.01832 -4.00000 -4.00000 -4.00000
-3 0.04979 -3.00000 -3.00000 -3.00000
-2 0.13534 -2.00000 -2.00000 -2.00000
-1 0.36788 -1.00000 -1.00000 -1.00000
0 1.00000 0.00000 0.00000 0.00000
1 2.71828 1.00000 1.00000 1.00000
2 7.38906 2.00000 2.00000 2.00000
3 20.08554 3.00000 3.00000 3.00000
4 54.59814 4.00000 4.00000 4.00000
5 148.41313 5.00000 5.00000 5.00000
The second column should contain the same data that the following columns contain. logf is returning a number that is approximately, but not exactly, equal to it's input.
Thanks for your help!
--
Jim Barrett
|
|
|
RE: trouble in libmath? - Aug. 24, '06, 10:38:16 PM
|
|
|
Rodney
Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
> BTW, adding "-I/usr/local/include -L/usr/local/lib" does not solve the problem.
Right, we haven't done any updates/extensions for libm.
For clarity I'm going to point out that libm is not the same as libmath.
These are two different libraries. Try doing "-lmath -lm".
|
|
|
RE: trouble in libmath? - Aug. 25, '06, 11:31:21 AM
|
|
|
markfunk
Posts: 673
Joined: Mar. 31, '03,
Status: offline
|
Did we always ship libmath.so with gcc ?
Or was this new in SFU 3.5 ?
Is libmath "encumbered" by the GPL or LGPL ?
|
|
|
RE: trouble in libmath? - Aug. 25, '06, 11:45:30 AM
|
|
|
eperea
Posts: 71
Joined: Apr. 6, '05,
Status: offline
|
I meant to ask where is the documentation for libmath.so, since "man math" refers to libm.so.
When I saw Rodney's original reply, I tried adding -lmath after -lm to the OP's command line, but it did not work. Using "-lmath -lm" did work.
|
|
|
RE: trouble in libmath? - Aug. 25, '06, 1:47:11 PM
|
|
|
Rodney
Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
> Did we always ship libmath.so with gcc ?
> Or was this new in SFU 3.5 ?
It shipped with 3.0 (it might have been with Firebrand
but I don't have that running anywhere right now).
> Is libmath "encumbered" by the GPL or LGPL ?
I'm not sure which, but it has to be one or the other.
> I meant to ask where is the documentation for libmath.so, since "man math" refers to libm.so.
There doesn't appear to be any additional page of info. There's no man page on logf either.
So I was thinking PSS would say it's not documented so you're SOL. But it's in the header file.
If I recall correctly (since I don't have a copy of the gcc libmath around) it's a C source of
some of the math API's. That why "-lmath -lm". I tried do nm on it to what's in it, but
it's stripped. In contrast, libm API's are all machine coded. I was surprised at the error because
the difference between log() and logf() is pretty minor.
|
|
|
RE: trouble in libmath? - Aug. 25, '06, 2:29:22 PM
|
|
|
Rodney
Posts: 3728
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
BTW this only affect version 3.5. Version 5.2 has been fixed.
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
|
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts |
|
|
|