Hello,
look this tiny C source code:

========

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

int main()
{
    double value = 0x1p1023;

    printf("log2=%.14f\n", log2(value));
#undef log2
    printf("log2=%.14f\n", log2(value));

    return 0;
}

========

Compile it with a simple command:

$ gcc test_log2.c -o test_log2.exe

and run it.
The result on the console is:

log2=1023.00000000000011
log2=1023.00000000000000

If you look inside math.h from newlib, you will see this code:

extern double log2 (double);
#if !defined(__cplusplus)
#define log2(x) (log (x) / _M_LN2)
#endif

As you can see, my simple test program just calculates log2() by using
log() function and next, after undefining log2() macro, it uses the
true log2() function.

Actually, that macro log2() "overloads" the log2() function.
And as result, the calculation of "(log (x) / _M_LN2)" loses the
precision on the last bits of the result.
It is not clear to me if there is a particular reason for doing so,
because this thing makes the Python's test suite to fail on the tests
for the log2() function.
What do you think?
Because log2() function was perfectly able to pass the tests.

Sincerely,

Carlo Bramini.

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to