Merge pull request #368 from lovell/builtin-isnan-isinf
Use gcc/clang isnan and isinf builtin functions, where available
This commit is contained in:
commit
89d1127de6
@ -322,7 +322,7 @@ vips_max_stop( VipsStatistic *statistic, void *seq )
|
||||
TYPE m; \
|
||||
\
|
||||
for( i = 0; i < sz && values->n < values->size; i++ ) \
|
||||
if( !isnan( p[i] ) ) \
|
||||
if( !VIPS_ISNAN( p[i] ) ) \
|
||||
vips_values_add( values, p[i], x + i / bands, y ); \
|
||||
m = values->value[0]; \
|
||||
\
|
||||
@ -342,7 +342,7 @@ vips_max_stop( VipsStatistic *statistic, void *seq )
|
||||
for( i = 0; i < sz && values->n < values->size; i++ ) { \
|
||||
TYPE mod2 = p[0] * p[0] + p[1] * p[1]; \
|
||||
\
|
||||
if( !isnan( mod2 ) ) \
|
||||
if( !VIPS_ISNAN( mod2 ) ) \
|
||||
vips_values_add( values, p[i], x + i / bands, y ); \
|
||||
\
|
||||
p += 2; \
|
||||
|
@ -325,7 +325,7 @@ vips_min_stop( VipsStatistic *statistic, void *seq )
|
||||
TYPE m; \
|
||||
\
|
||||
for( i = 0; i < sz && values->n < values->size; i++ ) \
|
||||
if( !isnan( p[i] ) ) \
|
||||
if( !VIPS_ISNAN( p[i] ) ) \
|
||||
vips_values_add( values, p[i], x + i / bands, y ); \
|
||||
m = values->value[0]; \
|
||||
\
|
||||
@ -345,7 +345,7 @@ vips_min_stop( VipsStatistic *statistic, void *seq )
|
||||
for( i = 0; i < sz && values->n < values->size; i++ ) { \
|
||||
TYPE mod2 = p[0] * p[0] + p[1] * p[1]; \
|
||||
\
|
||||
if( !isnan( mod2 ) ) \
|
||||
if( !VIPS_ISNAN( mod2 ) ) \
|
||||
vips_values_add( values, p[i], x + i / bands, y ); \
|
||||
\
|
||||
p += 2; \
|
||||
|
@ -273,9 +273,9 @@ vips_col_scRGB2sRGB( int range, int *lut,
|
||||
* Don't use isnormal(), it is false for 0.0 and for subnormal
|
||||
* numbers.
|
||||
*/
|
||||
if( isnan( R ) || isinf( R ) ||
|
||||
isnan( G ) || isinf( G ) ||
|
||||
isnan( B ) || isinf( B ) ) {
|
||||
if( VIPS_ISNAN( R ) || VIPS_ISINF( R ) ||
|
||||
VIPS_ISNAN( G ) || VIPS_ISINF( G ) ||
|
||||
VIPS_ISNAN( B ) || VIPS_ISINF( B ) ) {
|
||||
*r = 0;
|
||||
*g = 0;
|
||||
*b = 0;
|
||||
@ -370,9 +370,9 @@ vips_col_scRGB2BW( int range, int *lut, float R, float G, float B,
|
||||
* Don't use isnormal(), it is false for 0.0 and for subnormal
|
||||
* numbers.
|
||||
*/
|
||||
if( isnan( R ) || isinf( R ) ||
|
||||
isnan( G ) || isinf( G ) ||
|
||||
isnan( B ) || isinf( B ) ) {
|
||||
if( VIPS_ISNAN( R ) || VIPS_ISINF( R ) ||
|
||||
VIPS_ISNAN( G ) || VIPS_ISINF( G ) ||
|
||||
VIPS_ISNAN( B ) || VIPS_ISINF( B ) ) {
|
||||
*g = 0;
|
||||
|
||||
return( -1 );
|
||||
|
@ -40,6 +40,7 @@ extern "C" {
|
||||
#endif /*__cplusplus*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
/* Some platforms don't have M_PI :-(
|
||||
*/
|
||||
@ -157,6 +158,17 @@ G_STMT_START { \
|
||||
|
||||
#define VIPS_CLIP_NONE( V, SEQ ) {}
|
||||
|
||||
/* The built-in isnan and isinf functions provided by gcc 4+ and clang are
|
||||
* up to 7x faster than their libc equivalent included from <math.h>.
|
||||
*/
|
||||
#if defined(__clang__) || (__GNUC__ >= 4)
|
||||
#define VIPS_ISNAN( V ) __builtin_isnan( V )
|
||||
#define VIPS_ISINF( V ) __builtin_isinf( V )
|
||||
#else
|
||||
#define VIPS_ISNAN( V ) isnan( V )
|
||||
#define VIPS_ISINF( V ) isinf( V )
|
||||
#endif
|
||||
|
||||
/* Not all platforms have PATH_MAX (eg. Hurd) and we don't need a platform one
|
||||
* anyway, just a static buffer big enough for almost any path.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user