special case for **-1

Since it's very common.

See https://github.com/libvips/libvips/discussions/2352
This commit is contained in:
John Cupitt 2021-07-16 13:06:15 +01:00
parent b493b16e54
commit dd4b11063a
1 changed files with 9 additions and 4 deletions

View File

@ -137,11 +137,16 @@ vips_math2_build( VipsObject *object )
double left = (double) (X); \
double right = (double) (E); \
\
/* Division by zero! Difficult to report tho' \
/* Special case for **-1 and **0.5, since they are so common. Also \
* watch for /0. \
*/ \
(Y) = (right == 0.5) \
? sqrt( left ) \
: (left == 0.0 && right < 0.0) ? 0.0 : pow( left, right ); \
(Y) = (left == 0.0) \
? 0.0 \
: (right == -1) \
? 1.0 / left \
: (right == 0.5) \
? sqrt( left ) \
: pow( left, right ); \
}
#define WOP( Y, X, E ) POW( Y, E, X )