Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
304 changes: 159 additions & 145 deletions quaddtype/numpy_quaddtype/src/casts.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions quaddtype/numpy_quaddtype/src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ extern "C" {

// Quad precision constants using sleef_q macro
#define QUAD_PRECISION_ZERO sleef_q(+0x0000000000000LL, 0x0000000000000000ULL, -16383)
#define QUAD_PRECISION_NEG_ZERO sleef_q(-0x0000000000000LL, 0x0000000000000000ULL, -16383)
#define QUAD_PRECISION_ONE sleef_q(+0x1000000000000LL, 0x0000000000000000ULL, 0)
#define QUAD_PRECISION_INF sleef_q(+0x1000000000000LL, 0x0000000000000000ULL, 16384)
#define QUAD_PRECISION_NINF sleef_q(-0x1000000000000LL, 0x0000000000000000ULL, 16384)
#define QUAD_PRECISION_NAN sleef_q(+0x1ffffffffffffLL, 0xffffffffffffffffULL, 16384)
#define QUAD_PRECISION_NEG_NAN sleef_q(-0x1ffffffffffffLL, 0xffffffffffffffffULL, 16384)

// Additional constants
#define QUAD_PRECISION_MAX_FINITE SLEEF_QUAD_MAX
Expand Down
24 changes: 12 additions & 12 deletions quaddtype/numpy_quaddtype/src/dragon4.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,22 +974,22 @@ PrintInfNan(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa, npy_uint32

DEBUG_ASSERT(bufferSize > 0);

/* Print sign for both inf and nan values */
if (signbit == '+') {
if (pos < maxPrintLen - 1) {
buffer[pos++] = '+';
}
}
else if (signbit == '-') {
if (pos < maxPrintLen - 1) {
buffer[pos++] = '-';
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also make this change in NumPy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for the sake of completeness yeah, I am not sure of the actual usecase of -nan
An even important case is -0.0 as I've seen some people use it as signal and it is working correct in numpy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-0.0 is, unfortunately, quite important, so that you can go from e.g. -1/inf=-0 back to -1/-0=inf.

-NaN is more niche but worth preserving nonetheless


/* Check for infinity */
if (mantissa == 0) {
npy_uint32 printLen;

/* only print sign for inf values (though nan can have a sign set) */
if (signbit == '+') {
if (pos < maxPrintLen - 1) {
buffer[pos++] = '+';
}
}
else if (signbit == '-') {
if (pos < maxPrintLen - 1) {
buffer[pos++] = '-';
}
}

/* copy and make sure the buffer is terminated */
printLen = (3 < maxPrintLen - pos) ? 3 : maxPrintLen - pos;
memcpy(buffer + pos, "inf", printLen);
Expand Down
Loading