Skip to content

Instantly share code, notes, and snippets.

@cartazio
Created March 2, 2014 04:05
Show Gist options
  • Save cartazio/9301745 to your computer and use it in GitHub Desktop.
Save cartazio/9301745 to your computer and use it in GitHub Desktop.
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''
@cartazio
Copy link
Author

cartazio commented Mar 2, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment