core/vnl/vnl_rational_traits.cxx
Go to the documentation of this file.
00001 //:
00002 // \file
00003 // \author Peter Vanroose
00004 // \date   6 September 2002
00005 //
00006 //-----------------------------------------------------------------------------
00007 
00008 #include "vnl_rational_traits.h"
00009 #include <vcl_complex.h>
00010 #include <vcl_cmath.h>
00011 
00012 const vnl_rational vnl_numeric_traits<vnl_rational>::zero = vnl_rational(0L,1L);
00013 const vnl_rational vnl_numeric_traits<vnl_rational>::one = vnl_rational(1L,1L);
00014 const vnl_rational vnl_numeric_traits<vnl_rational>::maxval = vnl_rational(vnl_numeric_traits<long>::maxval,1L);
00015 
00016 const vcl_complex<vnl_rational> vnl_numeric_traits<vcl_complex<vnl_rational> >::zero
00017   = vcl_complex<vnl_rational>(vnl_rational(0L,1L),vnl_rational(0L,1L));
00018 const vcl_complex<vnl_rational> vnl_numeric_traits<vcl_complex<vnl_rational> >::one
00019   = vcl_complex<vnl_rational>(vnl_rational(1L,1L),vnl_rational(0L,1L));
00020 
00021 vnl_rational vnl_math_squared_magnitude(vcl_complex<vnl_rational> const& x)
00022 {
00023   return x.real()*x.real()+x.imag()*x.imag();
00024 }
00025 
00026 vnl_rational vnl_math_abs(vcl_complex<vnl_rational> const& x)
00027 {
00028   return vnl_rational(vcl_sqrt(double(x.real()*x.real()+x.imag()*x.imag())));
00029 }
00030 
00031 vcl_ostream& operator<<(vcl_ostream& os, vcl_complex<vnl_rational> x)
00032 {
00033   return os << x.real() << '+' << x.imag() << 'j';
00034 }