http://qs1969.pair.com?node_id=1189615


in reply to Re: solve cubic equations
in thread solve cubic equations

my \C = ( ( Δ1 + sqrt( Δ1 - 4 Δ0 + 0i) ) / 2 ).roots(3)[0];

Mathematically, your code is equivalent. (The arctan and cos are hidden inside roots.) Numerically, yours is potentially unstable. The first + in the line above might lose accuracy due to subtracting nearly-equal numbers. See Numerical Recipes, chapter 5.6. Unfortunately, sometimes we have to choose between code that looks nice and code that works.

The trouble with Perl 6 is that it's full of people who think it's a good idea to have a class called "Cool" which contains a hodgepodge of numerical and string-manipulation methods.