Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Imaginary / Complex numbers

by Elliott (Pilgrim)
on Jul 22, 2002 at 13:36 UTC ( [id://184034]=perlquestion: print w/replies, xml ) Need Help??

Elliott has asked for the wisdom of the Perl Monks concerning the following question:

Is there a standard way of handling imaginary and/or complex numbers in Perl?

I am writing a little utility (for fun - that's the kind of fun guy I am) to extract the roots of quartic equations and I have found that the square root of any negative number is returned as 2^31, which at least stops the script crashing but is otherwise not very helpful.

Is this OS-dependent?

Replies are listed 'Best First'.
Re: Imaginary / Complex numbers
by Ionitor (Scribe) on Jul 22, 2002 at 13:43 UTC
    I think you want Math::Complex from CPAN. This is probably the easiest and most standard way of handling it.
Re: Imaginary / Complex numbers
by Abigail-II (Bishop) on Jul 22, 2002 at 13:46 UTC
    Math::Complex is a standard module that comes with perl 5.8.0. You also might want to look into the PDL module. It has a lot of math functionality - though I'm not sure whether it actually has complex numbers.

    Abigail

      In 2002, there was basic support using PDL::Complex (which didn't have working matrix multiplication, and had an extra exposed dimension for real/imaginary, which caused problems). That still (as of 2.080) exists, but is now deprecated in favour of the "native complex" (C99) number functionality (cfloat, cdouble, cldouble types).
Re: Imaginary / Complex numbers
by dimmesdale (Friar) on Jul 22, 2002 at 13:45 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://184034]
Approved by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-18 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found