📄 vnl_numeric_traits.h
字号:
// This is vxl/vnl/vnl_numeric_traits.h
#ifndef vnl_numeric_traits_h_
#define vnl_numeric_traits_h_
#ifdef VCL_NEEDS_PRAGMA_INTERFACE
#pragma interface
#endif
//:
// \file
// \brief Templated zero/one/precision
//
// To allow templated numerical algorithms to determine appropriate
// values for zero, one, maxval, and types for double precision,
// maximum product etc.
//
// \author Andrew W. Fitzgibbon, Oxford RRG
// \date 04 Sep 96
//
// \verbatim
// Modifications:
// 980212 AWF Initial version.
// AWF 010498 Moved to math
// LSB (Manchester) 23/3/01 Documentation tidied
// Peter Vanroose 14/7/01 vnl_rational added
// Peter Vanroose 14/10/01 vnl_rational moved to vnl_rational.h
// AWF 250202 Add const T specializations for the basic types.
// \endverbatim
//
//-----------------------------------------------------------------------------
#include <vcl_complex_fwd.h>
#include <vxl_config.h> // for type vxl_uint_64
// this is an empty class template.
// only the specializations make sense.
#if !defined(VCL_VC70)
template <class T>
class vnl_numeric_traits;
#else
// However, *some* compilers require the template to be defined
// under some circumstances...
// Since the non-specialized template doesn't make any sense, make
// sure that any types "accidently" derived from it will cause
// compiler errors.
class vnl_numeric_traits_not_a_valid_type { };
template <class T>
class vnl_numeric_traits
{
public:
//: Additive identity
static const vnl_numeric_traits_not_a_valid_type zero;
//: Multiplicative identity
static const vnl_numeric_traits_not_a_valid_type one;
//: Maximum value which this type can assume
static const vnl_numeric_traits_not_a_valid_type maxval;
//: Return value of abs()
typedef vnl_numeric_traits_not_a_valid_type abs_t;
//: Name of a type twice as long as this one for accumulators and products.
typedef vnl_numeric_traits_not_a_valid_type double_t;
//: Name of type which results from multiplying this type with a double
typedef vnl_numeric_traits_not_a_valid_type real_t;
};
#endif
#ifndef NO_STD_BOOL
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<bool>
{
public:
//: Additive identity
static const bool zero VCL_STATIC_CONST_INIT_INT_DECL(false);
//: Multiplicative identity
static const bool one VCL_STATIC_CONST_INIT_INT_DECL(true);
//: Maximum value which this type can assume
static const bool maxval VCL_STATIC_CONST_INIT_INT_DECL(true);
//: Return value of abs()
typedef unsigned int abs_t;
//: Name of a type twice as long as this one for accumulators and products.
typedef unsigned int double_t;
//: Name of type which results from multiplying this type with a double
typedef double real_t;
};
#ifndef VCL_CAN_NOT_SPECIALIZE_CONST
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<bool const> : public vnl_numeric_traits<bool> {};
#endif
#endif
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<char>
{
public:
//: Additive identity
static const char zero VCL_STATIC_CONST_INIT_INT_DECL(0);
//: Multiplicative identity
static const char one VCL_STATIC_CONST_INIT_INT_DECL(1);
//: Maximum value which this type can assume.
// It is 127 (and not 255) since "char" is not guaranteed to be unsigned.
static const char maxval VCL_STATIC_CONST_INIT_INT_DECL(char(255)<0?127:255);
//: Return value of abs()
typedef unsigned char abs_t;
//: Name of a type twice as long as this one for accumulators and products.
typedef short double_t;
//: Name of type which results from multiplying this type with a double
typedef double real_t;
};
#ifndef VCL_CAN_NOT_SPECIALIZE_CONST
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<char const> : public vnl_numeric_traits<char> {};
#endif
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<unsigned char>
{
public:
//: Additive identity
static const unsigned char zero VCL_STATIC_CONST_INIT_INT_DECL(0);
//: Multiplicative identity
static const unsigned char one VCL_STATIC_CONST_INIT_INT_DECL(1);
//: Maximum value which this type can assume
static const unsigned char maxval VCL_STATIC_CONST_INIT_INT_DECL(255);
//: Return value of abs()
typedef unsigned char abs_t;
//: Name of a type twice as long as this one for accumulators and products.
typedef unsigned short double_t;
//: Name of type which results from multiplying this type with a double
typedef double real_t;
};
#ifndef VCL_CAN_NOT_SPECIALIZE_CONST
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<unsigned char const> : public vnl_numeric_traits<unsigned char> {};
#endif
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<signed char>
{
public:
//: Additive identity
static const signed char zero VCL_STATIC_CONST_INIT_INT_DECL(0);
//: Multiplicative identity
static const signed char one VCL_STATIC_CONST_INIT_INT_DECL(1);
//: Maximum value which this type can assume
static const signed char maxval VCL_STATIC_CONST_INIT_INT_DECL(127);
//: Return value of abs()
typedef unsigned char abs_t;
//: Name of a type twice as long as this one for accumulators and products.
typedef signed short double_t;
//: Name of type which results from multiplying this type with a double
typedef double real_t;
};
#ifndef VCL_CAN_NOT_SPECIALIZE_CONST
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<signed char const> : public vnl_numeric_traits<signed char> {};
#endif
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<short>
{
public:
//: Additive identity
static const short zero VCL_STATIC_CONST_INIT_INT_DECL(0);
//: Multiplicative identity
static const short one VCL_STATIC_CONST_INIT_INT_DECL(1);
//: Maximum value which this type can assume
static const short maxval; // = 0x7fff;
//: Return value of abs()
typedef unsigned short abs_t;
//: Name of a type twice as long as this one for accumulators and products.
typedef int double_t;
//: Name of type which results from multiplying this type with a double
typedef double real_t;
};
#ifndef VCL_CAN_NOT_SPECIALIZE_CONST
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<short const> : public vnl_numeric_traits<short> {};
#endif
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<unsigned short>
{
public:
//: Additive identity
static const unsigned short zero VCL_STATIC_CONST_INIT_INT_DECL(0);
//: Multiplicative identity
static const unsigned short one VCL_STATIC_CONST_INIT_INT_DECL(1);
//: Maximum value which this type can assume
static const unsigned short maxval; // = 0xffff;
//: Return value of abs()
typedef unsigned short abs_t;
//: Name of a type twice as long as this one for accumulators and products.
typedef unsigned int double_t;
//: Name of type which results from multiplying this type with a double
typedef double real_t;
};
#ifndef VCL_CAN_NOT_SPECIALIZE_CONST
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<unsigned short const> : public vnl_numeric_traits<unsigned short> {};
#endif
VCL_DEFINE_SPECIALIZATION
class vnl_numeric_traits<int>
{
public:
//: Additive identity
static const int zero VCL_STATIC_CONST_INIT_INT_DECL(0);
//: Multiplicative identity
static const int one VCL_STATIC_CONST_INIT_INT_DECL(1);
//: Maximum value which this type can assume
static const int maxval; // = 0x7fffffff;
//: Return value of abs()
typedef unsigned int abs_t;
//: Name of a type twice as long as this one for accumulators and products.
typedef long double_t;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -