From a2568d85895b29b79b0c83e419580fbabd4f3399 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 11 Mar 2024 19:29:44 -0700 Subject: [PATCH] Allow inline sqrt --- scheme/inexact.sld | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/scheme/inexact.sld b/scheme/inexact.sld index ab8c3376..a8d00c86 100644 --- a/scheme/inexact.sld +++ b/scheme/inexact.sld @@ -120,6 +120,28 @@ } " ; "(void *data, object ptr, object z)" ; " return_inexact_double_or_cplx_op_no_cps(data, ptr, sqrt, csqrt, z);" -) + "(void *data, object ptr, object z)" + " double complex unboxed; + Cyc_check_num(data, z); + if (obj_is_int(z)) { + unboxed = csqrt(obj_obj2int(z)); + } else if (type_of(z) == integer_tag) { + unboxed = csqrt(((integer_type *)z)->value); + } else if (type_of(z) == bignum_tag) { + unboxed = csqrt(mp_get_double(&bignum_value(z))); + } else if (type_of(z) == complex_num_tag) { + unboxed = csqrt(complex_num_value(z)); + assign_complex_num(ptr, unboxed); + return ptr; + } else { + unboxed = csqrt(((double_type *)z)->value); + } + + if (cimag(unboxed) == 0.0) { + assign_double(ptr, creal(unboxed)); + } else { + assign_double(ptr, unboxed); + } + return ptr; ") ))