11#include < sleef.h>
22#include < sleefquad.h>
33#include < cmath>
4+ #include < limits>
5+
6+ // Quad Constants, generated with qutil
7+ #define QUAD_ZERO sleef_q (+0x0000000000000LL , 0x0000000000000000ULL , -16383 )
8+ #define QUAD_ONE sleef_q (+0x1000000000000LL , 0x0000000000000000ULL , 0 )
9+ #define QUAD_POS_INF sleef_q (+0x1000000000000LL , 0x0000000000000000ULL , 16384 )
410
511// Unary Quad Operations
612typedef Sleef_quad (*unary_op_quad_def)(const Sleef_quad *);
@@ -20,8 +26,7 @@ quad_positive(const Sleef_quad *op)
2026static inline Sleef_quad
2127quad_sign (const Sleef_quad *op)
2228{
23- Sleef_quad zero = Sleef_cast_from_doubleq1 (0.0 );
24- int32_t sign = Sleef_icmpq1 (*op, zero);
29+ int32_t sign = Sleef_icmpq1 (*op, QUAD_ZERO);
2530 // sign(x=NaN) = x; otherwise sign(x) in { -1.0; 0.0; +1.0 }
2631 return Sleef_iunordq1 (*op, *op) ? *op : Sleef_cast_from_int64q1 (sign);
2732}
@@ -287,27 +292,23 @@ quad_signbit(const Sleef_quad *op)
287292{
288293 // FIXME @juntyr or @SwayamInSync: replace with binary implementation
289294 // once we test big and little endian in CI
290- Sleef_quad zero = Sleef_cast_from_doubleq1 (0.0 );
291- Sleef_quad one = Sleef_cast_from_doubleq1 (1.0 );
292- Sleef_quad one_signed = Sleef_copysignq1 (one, *op);
295+ Sleef_quad one_signed = Sleef_copysignq1 (QUAD_ONE, *op);
293296 // signbit(x) = 1 iff copysign(1, x) == -1
294- return Sleef_icmpltq1 (one_signed, zero );
297+ return Sleef_icmpltq1 (one_signed, QUAD_ZERO );
295298}
296299
297300static inline npy_bool
298301quad_isfinite (const Sleef_quad *op)
299302{
300303 // isfinite(x) = abs(x) < inf
301- Sleef_quad inf = Sleef_cast_from_doubleq1 (std::numeric_limits<double >::infinity ());
302- return Sleef_icmpltq1 (Sleef_fabsq1 (*op), inf);
304+ return Sleef_icmpltq1 (Sleef_fabsq1 (*op), QUAD_POS_INF);
303305}
304306
305307static inline npy_bool
306308quad_isinf (const Sleef_quad *op)
307309{
308310 // isinf(x) = abs(x) == inf
309- Sleef_quad inf = Sleef_cast_from_doubleq1 (std::numeric_limits<double >::infinity ());
310- return Sleef_icmpeqq1 (Sleef_fabsq1 (*op), inf);
311+ return Sleef_icmpeqq1 (Sleef_fabsq1 (*op), QUAD_POS_INF);
311312}
312313
313314static inline npy_bool
0 commit comments