* libm accuracy, eglibc compared to glibc
@ 2014-03-12 15:30 Mats Kärrman
2014-03-12 15:43 ` Stanacar, StefanX
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Mats Kärrman @ 2014-03-12 15:30 UTC (permalink / raw)
To: openembedded-core@lists.openembedded.org
Hi,
I face a problem with libm. With my Dora build the following assertion doesn't hold:
sqrt( pow( sqrt( 2.0 ), 4.0 ) ) == 2.0
1) With my old OE-classic / glibc-2.9 / PowerPC-hf it holds.
2) With my Debian desktop PC / glibc-2.17 / amd64 it holds.
3) With my new OE-core Dora / eglibc-2.18 / PowerPC-hf it doesn't hold.
Close enough one can think but the standardized test case I run requires the result to be 2.0.
A simple test program:
--------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
int main(){
double two = 2.0;
double four = 4.0;
double s1 = sqrt(two);
printf("sqrt(%.20f) = %.20f\n", two, s1);
double p = pow(s1, four);
printf("pow(%.20f, %.20f) = %.20f\n", s1, four, p);
double s2 = sqrt(p);
printf("sqrt(%.20f) = %.20f\n", p, s2);
}
--------------------------------------------------------------------
results from 1 and 2 (identical):
sqrt(2.00000000000000000000) = 1.41421356237309514547
pow(1.41421356237309514547, 4.00000000000000000000) = 4.00000000000000088818
sqrt(4.00000000000000088818) = 2.00000000000000000000
results from 3:
sqrt(2.00000000000000000000) = 1.41421356237309492343
pow(1.41421356237309492343, 4.00000000000000000000) = 3.99999999999999866773
sqrt(3.99999999999999866773) = 1.99999999999999955591
Does anyone know if this is a known "feature" of eglibc or know any other reason
for this difference?
Best Regards,
Mats
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: libm accuracy, eglibc compared to glibc
2014-03-12 15:30 libm accuracy, eglibc compared to glibc Mats Kärrman
@ 2014-03-12 15:43 ` Stanacar, StefanX
2014-03-12 15:58 ` Burton, Ross
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Stanacar, StefanX @ 2014-03-12 15:43 UTC (permalink / raw)
To: Mats.Karrman@tritech.se; +Cc: openembedded-core@lists.openembedded.org
Hello,
I just want to point out that this looks very similar to a qemuppc
machine bug we've seen before with libm and floor() call:
https://bugzilla.yoctoproject.org/show_bug.cgi?id=4854
It was fixed with:
http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=2a48e9007cc92fedfdb6919411859fb943eacc94
HTH,
Stefan
On Wed, 2014-03-12 at 15:30 +0000, Mats Kärrman wrote:
> Hi,
>
> I face a problem with libm. With my Dora build the following assertion doesn't hold:
>
> sqrt( pow( sqrt( 2.0 ), 4.0 ) ) == 2.0
>
> 1) With my old OE-classic / glibc-2.9 / PowerPC-hf it holds.
> 2) With my Debian desktop PC / glibc-2.17 / amd64 it holds.
> 3) With my new OE-core Dora / eglibc-2.18 / PowerPC-hf it doesn't hold.
>
> Close enough one can think but the standardized test case I run requires the result to be 2.0.
> A simple test program:
> --------------------------------------------------------------------
> #include <stdio.h>
> #include <math.h>
>
> int main(){
>
> double two = 2.0;
> double four = 4.0;
>
> double s1 = sqrt(two);
> printf("sqrt(%.20f) = %.20f\n", two, s1);
> double p = pow(s1, four);
> printf("pow(%.20f, %.20f) = %.20f\n", s1, four, p);
> double s2 = sqrt(p);
> printf("sqrt(%.20f) = %.20f\n", p, s2);
>
> }
> --------------------------------------------------------------------
>
> results from 1 and 2 (identical):
> sqrt(2.00000000000000000000) = 1.41421356237309514547
> pow(1.41421356237309514547, 4.00000000000000000000) = 4.00000000000000088818
> sqrt(4.00000000000000088818) = 2.00000000000000000000
>
> results from 3:
> sqrt(2.00000000000000000000) = 1.41421356237309492343
> pow(1.41421356237309492343, 4.00000000000000000000) = 3.99999999999999866773
> sqrt(3.99999999999999866773) = 1.99999999999999955591
>
> Does anyone know if this is a known "feature" of eglibc or know any other reason
> for this difference?
>
> Best Regards,
> Mats
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: libm accuracy, eglibc compared to glibc
2014-03-12 15:30 libm accuracy, eglibc compared to glibc Mats Kärrman
2014-03-12 15:43 ` Stanacar, StefanX
@ 2014-03-12 15:58 ` Burton, Ross
2014-03-13 7:45 ` Mats Kärrman
2014-03-12 17:37 ` Phil Blundell
2014-03-12 18:09 ` Khem Raj
3 siblings, 1 reply; 9+ messages in thread
From: Burton, Ross @ 2014-03-12 15:58 UTC (permalink / raw)
To: Mats Kärrman; +Cc: openembedded-core@lists.openembedded.org
On 12 March 2014 15:30, Mats Kärrman <Mats.Karrman@tritech.se> wrote:
> Does anyone know if this is a known "feature" of eglibc or know any other reason
> for this difference?
I expect the standard response from upstream here would be that
floating point mathematics isn't exact and if you want exact answers
then you should use a different representation. The differences start
at the first sqrt():
Test 1 and 2:
sqrt(2.00000000000000000000) = 1.41421356237309514547
Test 3:
sqrt(2.00000000000000000000) = 1.41421356237309492343
Test using bc and scale=30 (bc is fixed-point not floating-point):
sqrt(2.00000000000000000000) = 1.414213562373095048801688724209
The output from bc is a truncation of the "real" value of sqrt(2)
whereas both values from C's sqrt() function using floats are
approximations, both equally close. Why does your test case expect
the answer to be 2.0? That's a massive assumption to make, floats can
trivially lose accuracy rapidly as
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
explains.
Ross
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: libm accuracy, eglibc compared to glibc
2014-03-12 15:30 libm accuracy, eglibc compared to glibc Mats Kärrman
2014-03-12 15:43 ` Stanacar, StefanX
2014-03-12 15:58 ` Burton, Ross
@ 2014-03-12 17:37 ` Phil Blundell
2014-03-13 7:46 ` Mats Kärrman
2014-03-13 10:36 ` Mats Kärrman
2014-03-12 18:09 ` Khem Raj
3 siblings, 2 replies; 9+ messages in thread
From: Phil Blundell @ 2014-03-12 17:37 UTC (permalink / raw)
To: Mats Kärrman; +Cc: openembedded-core@lists.openembedded.org
On Wed, 2014-03-12 at 15:30 +0000, Mats Kärrman wrote:
> Does anyone know if this is a known "feature" of eglibc or know any other reason
> for this difference?
Does eglibc's own libm testsuite pass on your platform? I wonder if
oe-core is accidentally building eglibc without "big" libm for you, or
something like that. Might be worth checking your option-groups.config
to make sure.
p.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: libm accuracy, eglibc compared to glibc
2014-03-12 15:30 libm accuracy, eglibc compared to glibc Mats Kärrman
` (2 preceding siblings ...)
2014-03-12 17:37 ` Phil Blundell
@ 2014-03-12 18:09 ` Khem Raj
2014-03-13 7:51 ` Mats Kärrman
3 siblings, 1 reply; 9+ messages in thread
From: Khem Raj @ 2014-03-12 18:09 UTC (permalink / raw)
To: Mats Kärrman; +Cc: openembedded-core@lists.openembedded.org
Hi Mats
On Wed, Mar 12, 2014 at 8:30 AM, Mats Kärrman <Mats.Karrman@tritech.se> wrote:
> Hi,
>
> I face a problem with libm. With my Dora build the following assertion doesn't hold:
>
> sqrt( pow( sqrt( 2.0 ), 4.0 ) ) == 2.0
>
> 1) With my old OE-classic / glibc-2.9 / PowerPC-hf it holds.
> 2) With my Debian desktop PC / glibc-2.17 / amd64 it holds.
> 3) With my new OE-core Dora / eglibc-2.18 / PowerPC-hf it doesn't hold.
>
> Close enough one can think but the standardized test case I run requires the result to be 2.0.
> A simple test program:
> --------------------------------------------------------------------
> #include <stdio.h>
> #include <math.h>
>
> int main(){
>
> double two = 2.0;
> double four = 4.0;
>
> double s1 = sqrt(two);
> printf("sqrt(%.20f) = %.20f\n", two, s1);
> double p = pow(s1, four);
> printf("pow(%.20f, %.20f) = %.20f\n", s1, four, p);
> double s2 = sqrt(p);
> printf("sqrt(%.20f) = %.20f\n", p, s2);
>
> }
> --------------------------------------------------------------------
>
> results from 1 and 2 (identical):
> sqrt(2.00000000000000000000) = 1.41421356237309514547
> pow(1.41421356237309514547, 4.00000000000000000000) = 4.00000000000000088818
> sqrt(4.00000000000000088818) = 2.00000000000000000000
>
> results from 3:
> sqrt(2.00000000000000000000) = 1.41421356237309492343
> pow(1.41421356237309492343, 4.00000000000000000000) = 3.99999999999999866773
> sqrt(3.99999999999999866773) = 1.99999999999999955591
>
> Does anyone know if this is a known "feature" of eglibc or know any other reason
> for this difference?
>
We have done changes since OE-Classic days in the FPU area for ppc.
what ppc machine is it ? I have access to p2020 based machine (e500v2)
and it works as expected with
dora/eglibc-2.18
> Best Regards,
> Mats
> --
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: libm accuracy, eglibc compared to glibc
2014-03-12 15:58 ` Burton, Ross
@ 2014-03-13 7:45 ` Mats Kärrman
0 siblings, 0 replies; 9+ messages in thread
From: Mats Kärrman @ 2014-03-13 7:45 UTC (permalink / raw)
To: Burton, Ross; +Cc: openembedded-core@lists.openembedded.org
On Wednesday, March 12, 2014 4:58 PM, Burton, Ross wrote:
> On 12 March 2014 15:30, Mats Kärrman <Mats.Karrman@tritech.se> wrote:
>> Does anyone know if this is a known "feature" of eglibc or know any other reason
>> for this difference?
>
> I expect the standard response from upstream here would be that
> floating point mathematics isn't exact and if you want exact answers
> then you should use a different representation. The differences start
> at the first sqrt():
>
> Test 1 and 2:
> sqrt(2.00000000000000000000) = 1.41421356237309514547
> Test 3:
> sqrt(2.00000000000000000000) = 1.41421356237309492343
> Test using bc and scale=30 (bc is fixed-point not floating-point):
> sqrt(2.00000000000000000000) = 1.414213562373095048801688724209
>
> The output from bc is a truncation of the "real" value of sqrt(2)
> whereas both values from C's sqrt() function using floats are
> approximations, both equally close. Why does your test case expect
> the answer to be 2.0? That's a massive assumption to make, floats can
> trivially lose accuracy rapidly as
> http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
> explains.
I am aware of the problems with floating point math. The test cases are from IBM
and used to validate their J9 JVM on new platforms. AfaIk they normally work (as
they do for my old OE-classic system and for my Debian PC).
Any reason that EGLIBC should be different from GLIBC?
// Mats
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: libm accuracy, eglibc compared to glibc
2014-03-12 17:37 ` Phil Blundell
@ 2014-03-13 7:46 ` Mats Kärrman
2014-03-13 10:36 ` Mats Kärrman
1 sibling, 0 replies; 9+ messages in thread
From: Mats Kärrman @ 2014-03-13 7:46 UTC (permalink / raw)
To: Phil Blundell; +Cc: openembedded-core@lists.openembedded.org
On Wednesday, March 12, 2014 6:37 PM, Phil Blundell wrote:
> On Wed, 2014-03-12 at 15:30 +0000, Mats Kärrman wrote:
>> Does anyone know if this is a known "feature" of eglibc or know any other reason
>> for this difference?
>
> Does eglibc's own libm testsuite pass on your platform? I wonder if
> oe-core is accidentally building eglibc without "big" libm for you, or
> something like that. Might be worth checking your option-groups.config
> to make sure.
Thanks for the tip, I'll have a look.
// Mats
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: libm accuracy, eglibc compared to glibc
2014-03-12 18:09 ` Khem Raj
@ 2014-03-13 7:51 ` Mats Kärrman
0 siblings, 0 replies; 9+ messages in thread
From: Mats Kärrman @ 2014-03-13 7:51 UTC (permalink / raw)
To: Khem Raj; +Cc: openembedded-core@lists.openembedded.org
On Wednesday, March 12, 2014 7:09 PM, Khem Raj wrote:
> On Wed, Mar 12, 2014 at 8:30 AM, Mats Kärrman <Mats.Karrman@tritech.se> wrote:
>> I face a problem with libm. With my Dora build the following assertion doesn't hold:
>>
>> sqrt( pow( sqrt( 2.0 ), 4.0 ) ) == 2.0
>>
<snip>
>> Does anyone know if this is a known "feature" of eglibc or know any other reason
>> for this difference?
>>
> We have done changes since OE-Classic days in the FPU area for ppc.
> what ppc machine is it ? I have access to p2020 based machine (e500v2)
> and it works as expected with
> dora/eglibc-2.18
My machine is an e300c4.
I will try running the libm internal tests on my machine as Phil Blundell suggested.
BR // Mats
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: libm accuracy, eglibc compared to glibc
2014-03-12 17:37 ` Phil Blundell
2014-03-13 7:46 ` Mats Kärrman
@ 2014-03-13 10:36 ` Mats Kärrman
1 sibling, 0 replies; 9+ messages in thread
From: Mats Kärrman @ 2014-03-13 10:36 UTC (permalink / raw)
To: Phil Blundell; +Cc: openembedded-core@lists.openembedded.org
On Wednesday, March 12, 2014 6:37 PM, Phil Blundell wrote:
> On Wed, 2014-03-12 at 15:30 +0000, Mats Kärrman wrote:
>> Does anyone know if this is a known "feature" of eglibc or know any other reason
>> for this difference?
>
> Does eglibc's own libm testsuite pass on your platform? I wonder if
> oe-core is accidentally building eglibc without "big" libm for you, or
> something like that. Might be worth checking your option-groups.config
> to make sure.
I have no NFS set up so I have not managed to run the eglibc target tests yet.
I ran the test program I mentioned before on an i.MX6 (arm cortexa9-hf) system
built on Poky/Dora (the PowerPC system is bare-bone OE-core/Dora) and got the
correct results there (i.e identical to my PC et.c.).
Comparing:
.../eglibc/2.18-r0/build-powerpc-oe-linux/option-groups.config (my failing system)
.../eglibc/2.18-r0/build-arm-poky-linux-gnueabi/option-groups.config (arm i.MX6)
They are both identical and both have all options set "= Y".
My "home made" hard float tune for PowerPC looks like this:
------------------------------------------------------------------
# Tune for the e300c3 core
require conf/machine/include/tune-ppce300c3.inc
# Use hardware floating point
AVAILTUNES += "ppce300c3hf"
TUNE_FEATURES_tune-ppce300c3hf = "m32 fpu-hard ppce300c3"
TUNE_PKGARCH_tune-ppce300c3hf = "ppce300c3hf"
PACKAGE_EXTRA_ARCHS_tune-ppce300c3hf = "${PACKAGE_EXTRA_ARCHS_tune-powerpc} ppce300c3hf"
DEFAULTTUNE = "ppce300c3hf"
------------------------------------------------------------------
Your comments are welcome.
BR // Mats
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-03-13 10:36 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-12 15:30 libm accuracy, eglibc compared to glibc Mats Kärrman
2014-03-12 15:43 ` Stanacar, StefanX
2014-03-12 15:58 ` Burton, Ross
2014-03-13 7:45 ` Mats Kärrman
2014-03-12 17:37 ` Phil Blundell
2014-03-13 7:46 ` Mats Kärrman
2014-03-13 10:36 ` Mats Kärrman
2014-03-12 18:09 ` Khem Raj
2014-03-13 7:51 ` Mats Kärrman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox