From abf224218bb3ce3417f4a1952efa4f2bcf5d24c5 Mon Sep 17 00:00:00 2001 From: "Tarn W. Burton" Date: Tue, 3 Sep 2024 07:38:28 -0400 Subject: [PATCH] Allow sqrt to downcast --- include/clasp/core/numbers.h | 6 +++--- src/core/numbers.cc | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/clasp/core/numbers.h b/include/clasp/core/numbers.h index 5aa1367bb3..ef7ed5a383 100644 --- a/include/clasp/core/numbers.h +++ b/include/clasp/core/numbers.h @@ -706,11 +706,11 @@ inline Number_sp clasp_divide(Number_sp na, Number_sp nb) { return contagion_div inline int clasp_number_compare(Number_sp x, Number_sp y) { return basic_compare(x, y); }; -template inline Number_sp _sqrt(Float f) { +template inline Number_sp _sqrt(Float1 f) { if (std::signbit(f)) - return Complex_O::create(make_number(Float{0.0}), make_number(std::sqrt(-f))); + return Complex_O::create(make_number(Float2{0.0}), make_number(static_cast(std::sqrt(-f)))); - return make_number(std::sqrt(f)); + return make_number(static_cast(std::sqrt(f))); } inline Number_sp clasp_log1(Number_sp x) { diff --git a/src/core/numbers.cc b/src/core/numbers.cc index fde4aca936..9a7d8de07f 100644 --- a/src/core/numbers.cc +++ b/src/core/numbers.cc @@ -1768,7 +1768,7 @@ Number_sp Ratio_O::signum_() const { return clasp_signum(this->_numerator); } -Number_sp Ratio_O::sqrt_() const { return _sqrt(this->as_float_()); } +Number_sp Ratio_O::sqrt_() const { return _sqrt(this->as_double_()); } Number_sp Ratio_O::reciprocal_() const { Integer_sp num = this->_numerator, denom = this->_denominator; @@ -1894,7 +1894,7 @@ Number_sp LongFloat_O::sqrt_() const { return _sqrt(_Value); } Number_sp Complex_O::sqrt_() const { return cl__expt(this->asSmartPtr(), _lisp->plusHalf()); } -Number_sp Bignum_O::sqrt_() const { return _sqrt(cast()); } +Number_sp Bignum_O::sqrt_() const { return _sqrt(cast()); } Number_sp Bignum_O::reciprocal_() const { if (this->minusp_())