|
From: Stavros M. <mac...@gm...> - 2025-12-01 17:21:17
|
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. > Can you give some examples? Are you thinking of, say, cabs((x+1e200)+%i)? That only overflows if you expand the result.... And I agree that basic *cabs* shouldn't worry about cases like this. > 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 agree that this would be odd, but maybe we should consider it. After all, we *do* currently convert floats to rats in some cases. For example, *keepfloat* doesn't prevent *solve* from rationalizing, so that *solve(x^2+1e200*x-1) *doesn't overflow -- it returns rationals. I don't love that behavior, but generalizing the classic Forsythe paper <http://i.stanford.edu/pub/cstr/reports/cs/tr/66/40/CS-TR-66-40.pdf> for the general case of *solve* seems hard.... > 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. > For the purely numeric case, we should do as well as existing purely numeric libraries, which are pretty good at *cabs, *etc. > ------------------------------ > > *[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 > |