1
1
#include < sleef.h>
2
2
#include < sleefquad.h>
3
3
#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 )
4
10
5
11
// Unary Quad Operations
6
12
typedef Sleef_quad (*unary_op_quad_def)(const Sleef_quad *);
@@ -20,8 +26,7 @@ quad_positive(const Sleef_quad *op)
20
26
static inline Sleef_quad
21
27
quad_sign (const Sleef_quad *op)
22
28
{
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);
25
30
// sign(x=NaN) = x; otherwise sign(x) in { -1.0; 0.0; +1.0 }
26
31
return Sleef_iunordq1 (*op, *op) ? *op : Sleef_cast_from_int64q1 (sign);
27
32
}
@@ -287,27 +292,23 @@ quad_signbit(const Sleef_quad *op)
287
292
{
288
293
// FIXME @juntyr or @SwayamInSync: replace with binary implementation
289
294
// 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);
293
296
// signbit(x) = 1 iff copysign(1, x) == -1
294
- return Sleef_icmpltq1 (one_signed, zero );
297
+ return Sleef_icmpltq1 (one_signed, QUAD_ZERO );
295
298
}
296
299
297
300
static inline npy_bool
298
301
quad_isfinite (const Sleef_quad *op)
299
302
{
300
303
// 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);
303
305
}
304
306
305
307
static inline npy_bool
306
308
quad_isinf (const Sleef_quad *op)
307
309
{
308
310
// 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);
311
312
}
312
313
313
314
static inline npy_bool
0 commit comments