On Tue, Jul 07, 2026 at 07:49:10PM +0800, Qian Yun wrote:
> Commit 2f9e0af1 is totally correct, and LLM suggests
> 2 improvements:
>
> 1. use a function to compute sqrt(c^2+d^2), to avoid
> overflow, it is typically called "hypot".
I was thinking about this, but ATM I decided to skip it. There
3 main users of 'sqrt': R=RealClosure(FRAC(INT)), R=Float
and R=DoubleFlat. RealClosure is exact, so no accuracy problems.
Float does not overflow, so also no problem. In case of
DoubleFlat our code in general does not make significant effort
to avoid overflow, rather assumes that users will keep numbers
in reasonable range. This could change in the future, but
ATM I prefer to keep this.
> 2. avoids accuracy loss in the computation of xa or xb.
> This improves the test case you added.
Thanks, please commit.
> --- a/src/algebra/gaussian.spad
> +++ b/src/algebra/gaussian.spad
> @@ -353,10 +353,10 @@
> s2 := sqrt(s)
> if d < 0 then
> s2 := -s2
> - complex(s2*xa/d, s2)
> + complex(d/(2::R*s2), s2)
> s := xa/(2::R)
> s2 := sqrt(s)
> - complex(s2, s2*xb/d)
> + complex(s2, d/(2::R*s2))
>
> if R has TranscendentalFunctionCategory then
> half := recip(2::R)::R
>
> - Qian
>
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
fricas-devel...@googlegroups.com.
> To view this discussion visit
https://groups.google.com/d/msgid/fricas-devel/3974ccd4-cd1e-4a75-a8de-247b8d7ebaef%40gmail.com.
--
Waldek Hebisch