Red Hat Bugzilla – Bug 34631
libm log2() call returning always 0.000
Last modified: 2016-11-24 07:22:04 EST
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [de] (X11; U; Linux 2.4.2-0.1.49 i686)
After double checking with a simple testprogram i discovered that the
log2() call in libm (which is part of glibc) always returns 0.000 for any
Steps to Reproduce:
1. Write a simple program to calculate log2()
2. Check returned value
Actual Results: log2() return 0.0000
Expected Results: log2() should have returned the expected mathematical
results of the logarithmus on base 2.
Created attachment 14583 [details]
log2() test program
Created attachment 14584 [details]
Correct log2() implementation
I guess you forgot to use either -std=c99 or -D_ISOC99_SOURCE on the gcc
command line (or -D_GNU_SOURCE).
log2() is a ISO C99 standard function or part of GNU extensions.
Glibc supports many standards and needs to keep namespace clean.
If you compiled your testcase with -Wall, you'd see warning about implicit
declaration of log2 (and as implicit prototype is returning int, there is no
wonder you get wrong results).