trizen / Math-AnyNum

Math::AnyNum - transparent interface to Math::GMPq, Math::GMPz, Math::MPFR and Math::MPC.
https://metacpan.org/pod/Math::AnyNum
Artistic License 2.0
0 stars 1 forks source link

gaussian #2

Open bobmath opened 6 years ago

bobmath commented 6 years ago

This module is called "AnyNum", but it doesn't support Gaussian integers and Gaussian rationals (complex numbers where the components are integers or rationals instead of floating point). This is a common oversight in mathematical software. https://en.wikipedia.org/wiki/Gaussian_integer

trizen commented 6 years ago

Good point. However, Math::AnyNum is just providing an interface to the GMP, MPFR and MPC libraries, where the complex-number library (MPC) is providing support only for floating-point complex numbers.

Implementing support for Gaussian integers is not planned in the near future, but it is an interesting idea. Alternatively, a separate CPAN module, using Math::AnyNum (or Math::GMPz / Math::GMPq directly), would also be a good idea.

trizen commented 6 years ago

I'm working on a new module, called Math::GComplex (contributions are very welcomed), which will try to provide a generic interface to complex-number operations, accepting any kind of numerical objects for the components of complex numbers (including Math::AnyNum objects).

Here is a code snippet:

use 5.010;
use Math::GComplex;
use Math::AnyNum qw(:overload);

my $x = Math::GComplex->new(3, 4);
my $y = Math::GComplex->new(7, 5);

say $x + $y;        #=> (10 9)
say $x - $y;        #=> (-4 -1)
say $x * $y;        #=> (1 43)
say $x / $y;        #=> (41/74 13/74)

Repository: https://github.com/trizen/Math-GComplex