Skip to content

Commit 071a145

Browse files
committed
add workaround for older boost version
1 parent dddaa30 commit 071a145

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/rdf4cpp/BigDecimal.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,25 @@ struct BigDecimal {
435435
return false;
436436
}
437437

438+
static double cast_unscaled_to_double_safe(UnscaledValue_t const &value) noexcept {
439+
// There is a bug in boost versions <1.86.0
440+
// that can cause a crash in the cast `static_cast<double>(cpp_int)`
441+
// https://github.com/boostorg/multiprecision/issues/553
442+
443+
#if BOOST_VERSION < 108600
444+
// workaround from https://github.com/scylladb/scylladb/commit/51d09e6a2a407ea9b9ad380ba30e5558a25bb8be#diff-81e6758bbedbe566a51706c5af1ea68be225c36feb68983c3de0a69138f01264R73
445+
static auto const min = UnscaledValue_t{std::numeric_limits<double>::lowest()};
446+
static auto const max = UnscaledValue_t{std::numeric_limits<double>::max()};
447+
if (value < min) {
448+
return -std::numeric_limits<double>::infinity();
449+
} else if (value > max) {
450+
return std::numeric_limits<double>::infinity();
451+
}
452+
#endif // BOOST_VERSION
453+
454+
return static_cast<double>(value);
455+
}
456+
438457
public:
439458
/**
440459
* unary minus of this BigDecimal.
@@ -760,7 +779,7 @@ struct BigDecimal {
760779
* @return
761780
*/
762781
[[nodiscard]] explicit operator double() const noexcept {
763-
double const v = static_cast<double>(unscaled_value) * std::pow(static_cast<double>(base), -static_cast<double>(exponent));
782+
double const v = cast_unscaled_to_double_safe(unscaled_value) * std::pow(cast_unscaled_to_double_safe(base), -cast_unscaled_to_double_safe(exponent));
764783
if (!std::isnan(v) && !std::isinf(v))
765784
return v;
766785
// even Javas BigDecimal has no better solution

0 commit comments

Comments
 (0)