Skip to content

Commit dde4a84

Browse files
committed
improve error msg
1 parent 5c5d791 commit dde4a84

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

quaddtype/numpy_quaddtype/src/casts.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,21 @@ quad_to_string_same_value_check(quad_value in_val, const char *str_buf, npy_intp
427427
return 1;
428428
}
429429

430-
PyErr_Format(PyExc_ValueError,
431-
"QuadPrecision value cannot be represented exactly in target string dtype "
432-
"(string width too narrow or precision loss occurred)");
430+
// Values don't match - the string width is too narrow for exact representation
431+
// Sleef_quad sleef_val = quad_to_sleef_quad(&in_val, backend);
432+
Sleef_quad sleef_val = in_val.sleef_value;
433+
const char *val_str = quad_to_string_adaptive_cstr(&sleef_val, QUAD_STR_WIDTH);
434+
if (val_str != NULL) {
435+
PyErr_Format(PyExc_ValueError,
436+
"QuadPrecision value '%s' cannot be represented exactly in target string dtype "
437+
"(string width too narrow or precision loss occurred)",
438+
val_str);
439+
}
440+
else {
441+
PyErr_SetString(PyExc_ValueError,
442+
"QuadPrecision value cannot be represented exactly in target string dtype "
443+
"(string width too narrow or precision loss occurred)");
444+
}
433445
return -1;
434446
}
435447

0 commit comments

Comments
 (0)