Changeset 887


Ignore:
Timestamp:
Sep 2, 2011, 2:06:18 AM (8 years ago)
Author:
sam
Message:

test: implement a custom isnan()

This version is faster (about 25% on x86_64) and works when extreme
optimisation options such as -ffast-math are used.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/half.cpp

    r879 r887  
    2222#include "core.h"
    2323
    24 /* This will not work with aggressive optimisation, but a reasonable
    25  * assumption is that such environments do have a proper isnan(). */
     24/* Ensure isnan() is present even on systems that don't define it, or
     25 * when -ffast-math is being used. */
     26#if defined __FAST_MATH__
     27#   undef isnan
     28#endif
    2629#if !defined isnan
    27 #   define isnan(x) (!((x) == (x)))
     30static inline int isnan(float f)
     31{
     32    union { float f; uint32_t x; } u = { f };
     33    return (~u.x << 1) < 0x00fffffeu;
     34}
    2835#endif
    2936
Note: See TracChangeset for help on using the changeset viewer.