vnl_rational_traits.h
Go to the documentation of this file.
1 // This is core/vnl/vnl_rational_traits.h
2 #ifndef vnl_rational_traits_h_
3 #define vnl_rational_traits_h_
4 //:
5 // \file
6 // \brief numeric traits for vnl_rational
7 
8 #include <iosfwd>
9 #include <vnl/vnl_rational.h>
10 #include <vnl/vnl_numeric_traits.h>
11 #ifdef _MSC_VER
12 # include <vcl_msvc_warnings.h>
13 #endif
14 #include <vnl/vnl_export.h>
15 
16 template <>
18 {
19  public:
20  //: Additive identity
21  static VNL_EXPORT const vnl_rational zero; // = 0L
22  //: Multiplicative identity
23  static VNL_EXPORT const vnl_rational one; // = 1L
24  //: Maximum value which this type can assume
25  static VNL_EXPORT const vnl_rational maxval; // = vnl_numeric_traits<long>::maxval;
26  //: Return value of abs()
28  //: Name of a type twice as long as this one for accumulators and products.
30  //: Name of type which results from multiplying this type with a double.
31  // Note that this requires an explicit cast from double to vnl_rational.
32  // This must be a built-in type: do not set this to vnl_rational, since
33  // that would require std::sqrt(vnl_rational) etc., which is not allowed.
34  typedef double real_t;
35 };
36 
37 template <>
38 class vnl_numeric_traits<vnl_rational const> : public vnl_numeric_traits<vnl_rational>
39 {
40 };
41 
42 std::ostream& operator<<(std::ostream&, const std::complex<vnl_rational>&);
43 
44 template <>
45 class vnl_numeric_traits<std::complex<vnl_rational> >
46 {
47  public:
48  //: Additive identity
49  static const std::complex<vnl_rational> zero; // = std::complex<vnl_rational>(0L,0L)
50  //: Multiplicative identity
51  static const std::complex<vnl_rational> one; // = std::complex<vnl_rational>(1L,0L)
52  //: Maximum value which this type can assume; makes no sense for this type
53  static const std::complex<vnl_rational> maxval;
54  //: Return value of abs()
56  //: Name of a type twice as long as this one for accumulators and products.
57  typedef std::complex<vnl_rational> double_t;
58  //: Name of type which results from multiplying this type with a double
59  typedef std::complex<vnl_rational> real_t; // should be std::complex<double>, but that gives casting problems
60 };
61 
62 template <>
63 class vnl_numeric_traits<std::complex<vnl_rational> const> : public vnl_numeric_traits<std::complex<vnl_rational> >
64 {
65 };
66 
67 namespace vnl_math
68 {
69  vnl_rational squared_magnitude(std::complex<vnl_rational> const& );
70  vnl_rational abs(std::complex<vnl_rational> const& );
71 }
72 
73 #endif // vnl_rational_traits_h_
static const std::complex< vnl_rational > maxval
Maximum value which this type can assume; makes no sense for this type.
vnl_rational double_t
Name of a type twice as long as this one for accumulators and products.
static const std::complex< vnl_rational > one
Multiplicative identity.
Templated zero/one/precision.
vnl_rational abs_t
Return value of abs().
static const std::complex< vnl_rational > zero
Additive identity.
double real_t
Name of type which results from multiplying this type with a double.
real numerical constants.
Definition: vnl_bignum.h:430
vnl_bignum squared_magnitude(vnl_bignum const &x)
Definition: vnl_bignum.h:433
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
Definition: vnl_decnum.h:393
static VNL_EXPORT const vnl_rational one
Multiplicative identity.
std::complex< vnl_rational > double_t
Name of a type twice as long as this one for accumulators and products.
static VNL_EXPORT const vnl_rational zero
Additive identity.
vnl_bignum abs(vnl_bignum const &x)
Definition: vnl_bignum.h:432
static VNL_EXPORT const vnl_rational maxval
Maximum value which this type can assume.
std::complex< vnl_rational > real_t
Name of type which results from multiplying this type with a double.
High-precision rational numbers.
High-precision rational numbers.
Definition: vnl_rational.h:73