|
From: Stavros M. <mac...@gm...> - 2025-12-01 16:56:06
|
We should be able to do this right. The classic algorithms for complex
numbers are well documented (and pretty simple).
For more complicated things like say Z: 1e140*x + %i*1e+170, cabs(Z), it's
not much more complicated. It goes something like this:
risplit(Z) => [1e140*x, %i*1e+170]; map('numericcoeff,%%) => [1e140,
1e170]... and then
Something like cabs(multthru(1e-155*Z))*1e155 does the trick.
On Mon, Dec 1, 2025 at 11:03 AM Raymond Toy via Maxima-bugs <
max...@li...> wrote:
> Here's one way for doing cabs(x+%i*y), where x is a number. Divide by the
> arg by sqrt(x) to get cabs(sqrt(x)+%i*y/sqrt(x)) = sqrt(y^2/x+x). The
> final answer will be sqrt(x)*sqrt(y^2/x+x). Something similiar if y is a
> number.
>
> I don't know how to do this if both x and y are more complicated
> expressions composed of numbers + variables.
>
> One alternative is to convert the floats to bfloats if we get an overflow.
> We don't normally do that anywhere else, so this would be very odd.
>
> I don't think a nounform would be a bad answer, if we printed a warning
> that there would be a potential overflow when computing the result. I
> personally think if a user is doing numerical stuff, it's his responsiblity
> to deal with numerical issues that might arise. We'll be careful to limit
> overflows, but we can't solve all the potential numerical issues that might
> arise.
> ------------------------------
>
> *[bugs:#4638] <https://sourceforge.net/p/maxima/bugs/4638/>
> cabs/carg/polarform overflow and underflow*
>
> *Status:* open
> *Group:* None
> *Labels:* cabs carg
> *Created:* Sat Nov 29, 2025 07:18 AM UTC by Stavros Macrakis
> *Last Updated:* Mon Dec 01, 2025 02:21 PM UTC
> *Owner:* nobody
>
> cabs and carg on complex floats overflow and underflow even when the
> result is perfectly representable:
>
> cabs(1e-170 + %i*1e-170) => 0.0
> but float(cabs(bfloat(1e-170 + %i*1e-170))) => 1.414213562373095e-170
> cabs(1e170 + %i*1e+170) => overflow
> but float(cabs(bfloat(1e170 + %i*1e170))) => 1.4142135623730952e170
> carg(1e170 + %i*1e+170)) => overflow
> but float(carg(bfloat(1e170 + %i*1e+170))) => 0.7853981633974483
> carg(1e-310 + %i*1e-310) => overflow
> but carg(1b-310 + %i*1b-310) => 7.853981633974483b-1
> polarform(1e170 + %i*1e+170) => overflow
>
> Tested in Maxima 5.48.1 SBCL 2.5.7 MacOS Intel
> ------------------------------
>
> Sent from sourceforge.net because max...@li... is
> subscribed to https://sourceforge.net/p/maxima/bugs/
>
> To unsubscribe from further messages, a project admin can change settings
> at https://sourceforge.net/p/maxima/admin/bugs/options. Or, if this is a
> mailing list, you can unsubscribe from the mailing list.
> _______________________________________________
> Maxima-bugs mailing list
> Max...@li...
> https://lists.sourceforge.net/lists/listinfo/maxima-bugs
>
|