This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFA: Add definition of M_LOG2_E when compiling in ISO C99 mode


Thanks Nick for pointing this out. I have made a patch, slightly different than yours, that fixes the problem. Basically, I just defined a macro _M_LOG2E that is defined regardless. The macro is used by log2 and log2f and M_LOG2E uses it as well.

-- Jeff J.

Nick Clifton wrote:
Hi Jeff,

  I ran across a small problem with the definition of the log2 macro
  in newlib/libc/include/math.h.  The problem is that the macro is
  defined when compiling in ISO C99 mode, but that the M_LOG2_E value
  that it uses is not.  Here is an example:

    % cat foo.c
    #include <math.h>
    int main (void) { return (int) log2 (0.0); }

    % newlib-using-gcc -std=c99 -c foo.c
    foo.c: In function 'main':
    foo.c:2: error: 'M_LOG2_E' undeclared (first use in this function)

  The patch below fixes this problem by adding a definition of M_LOG2_E
  if the log2 macro has been defined but the constant has not.

OK to apply ?

Cheers
  Nick

newlib/ChangeLog
2007-09-06  Nick Clifton  <nickc@redhat.com>

	* libc/include/math.h (M_LOG2_E): Ensure that this macro is
	defined if the log2 macro is defined.

Index: newlib/libc/include/math.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/math.h,v
retrieving revision 1.28
diff -c -3 -p -r1.28 math.h
*** newlib/libc/include/math.h 11 Jul 2007 18:09:08 -0000 1.28
--- newlib/libc/include/math.h 6 Sep 2007 11:33:55 -0000
*************** extern __IMPORT _LIB_VERSION_TYPE _LIB_V
*** 464,469 ****
--- 464,473 ----
#endif /* ! defined (__STRICT_ANSI__) */
+ #if defined log2 && ! defined M_LOG2_E
+ #define M_LOG2_E 0.693147180559945309417
+ #endif
+ _END_STD_C
#ifdef __FAST_MATH__




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]