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: math.h float_t and double_t not typedef'ed when FLT_EVAL_METHOD defined


On 12/19/2012 04:40 AM, Jordy Potman wrote:
On 12/18/2012 11:40 PM, Jeff Johnston wrote:
On 12/18/2012 05:36 PM, Jeff Johnston wrote:
On 12/18/2012 04:43 PM, Craig Howland wrote:
Jeff:
      The first alteration is fine, but the second (no checks on log2f
macro) stops the patch from fixing the issue that Jordy Portman
reported
at the start of this thread.  If we want that issue to be fixed, either
the log2f macro needs to be deleted now, or else the added gates/checks
would need to go back.  I don't care much either way.  The gates
preserve the small speed increase (1 function call overhead) gained by
the macro for those cases where it is used (probably almost all uses
because nobody complained before Jordy did), but do make it messier.
                 Craig


Oh, so in Jordy's case, the value of FLT_EVAL_METHOD is set but not 0, 1, or 2? Otherwise, it is covered.


I will remove the macro.



Just for the record, the issue was that the original code in Newlib's math.h did not typedef float_t at all when FLT_EVAL_METHOD was already defined because the code was just:

#ifndef FLT_EVAL_METHOD
#define FLT_EVAL_METHOD 0
typedef float float_t;
typedef double double_t;
#endif /* FLT_EVAL_METHOD */

This caused an issue when float.h is included before math.h and the
log2f macro is used because float.h defines FLT_EVAL_METHOD, so math.h
would not typedef float_t, but the log2f macro would use float_t.

In my case (clang based compiler) FLT_EVAL_METHOD is set to
__FLT_EVAL_METHOD__ in float.h and __FLT_EVAL_METHOD__ is set to 0 by
default. So for my case the issue would have been fixed without removing
the log2f macro.

Jordy

Thanks Jordy for confirming.


I removed the macro regardless because I really don't like it. The log2f function is written with the same logic and should be replaced with an implementation similar to the other log functions and thereby improving its accuracy. There is a BSD version I found that I will eventually put into newlib so the macro will be obsoleted anyway. Float division isn't a good idea and anybody who really wants that form of implementation can simply do the division themselves and avoid the call to log2f.

-- Jeff J.

-- Jeff J.

-- Jeff J.

On 12/18/2012 04:26 PM, Jeff Johnston wrote:
I have checked in a modified version of the patch.

For implementation-defined FLT_EVAL_METHOD values, it will be assumed
that float_t and double_t have been defined for the configuration
(e.g. config.h or ieeefp.h).

I have removed the _FLOAT_T_DEFINED and _DOUBLE_T_DEFINED flags and
the check in the log2f macro.  I have also defaulted float_t to float
and double_t to double if FLT_EVAL_METHOD is not defined as was done
prior to the patch.

In the future, I intend to remove the log2f macro and replace the
log2f function with the BSD version which is consistent with the other
log functions.

-- Jeff J.







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