Created
March 2, 2014 04:05
-
-
Save cartazio/9301745 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance (RealFloat a) => Fractional (Complex a) where | |
{-# SPECIALISE instance Fractional (Complex Float) #-} | |
{-# SPECIALISE instance Fractional (Complex Double) #-} | |
(x:+y) / (x':+y') = (x*x''+y*y'') / d :+ (y*x''-x*y'') / d | |
where x'' = scaleFloat k x' | |
y'' = scaleFloat k y' | |
k = - max (exponent x') (exponent y') | |
d = x'*x'' + y'*y'' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2 Naive and non-naive algorithms
6
Fig. 3:
Smith’s algorithm for the complex division.
function z = compdiv_smith ( x , y )
a = real(x); b = imag(x);
c = real(y); d = imag(y);
if ( abs(d) <= abs(c) ) then
r = d/c
den = c + d * r
e = (a + b * r) / den
f = (b - a * r) / den
else
r = c/d
den = c * r + d
e = (a * r + b) / den
f = (b * r - a) / den