37 #ifndef VIGRA_NUMERICTRAITS_HXX 
   38 #define VIGRA_NUMERICTRAITS_HXX 
   44 #include "metaprogramming.hxx" 
   45 #include "sized_int.hxx" 
  464         template <
typename s, 
typename t>
 
  465         inline static t clamp_integer_to_unsigned(s value, t maximum) {
 
  469                 (value >= static_cast<s>(maximum) ? maximum : static_cast<t>(value));
 
  472         template <
typename s, 
typename t>
 
  473         inline static t clamp_integer_to_signed(s value, t minimum, t maximum) {
 
  475                 value <= static_cast<s>(minimum) ?
 
  477                 (value >= static_cast<s>(maximum) ? maximum : 
static_cast<t
>(value));
 
  480         template <
typename s, 
typename t>
 
  481         inline static t clamp_float_to_unsigned(s value, t maximum) {
 
  485                 (value >= static_cast<s>(maximum) ? maximum : static_cast<t>(value + 0.5));
 
  488         template <
typename s, 
typename t>
 
  489         inline static t clamp_float_to_signed(s value, t minimum, t maximum) {
 
  491                 return value >= 
static_cast<s
>(maximum) ? maximum : static_cast<t>(value + 0.5);
 
  493                 return value <= static_cast<s>(minimum) ? minimum : static_cast<t>(value - 0.5);
 
  498 struct Error_NumericTraits_not_specialized_for_this_case { };
 
  499 struct Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char { };
 
  504     typedef Error_NumericTraits_not_specialized_for_this_case Type;
 
  505     typedef Error_NumericTraits_not_specialized_for_this_case Promote;
 
  506     typedef Error_NumericTraits_not_specialized_for_this_case UnsignedPromote;
 
  507     typedef Error_NumericTraits_not_specialized_for_this_case RealPromote;
 
  508     typedef Error_NumericTraits_not_specialized_for_this_case ComplexPromote;
 
  509     typedef Error_NumericTraits_not_specialized_for_this_case ValueType;
 
  511     typedef Error_NumericTraits_not_specialized_for_this_case isScalar;
 
  512     typedef Error_NumericTraits_not_specialized_for_this_case isIntegral;
 
  513     typedef Error_NumericTraits_not_specialized_for_this_case isSigned;
 
  514     typedef Error_NumericTraits_not_specialized_for_this_case isOrdered;
 
  515     typedef Error_NumericTraits_not_specialized_for_this_case isComplex;
 
  519 struct NumericTraits<char>
 
  521     typedef Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char Type;
 
  522     typedef Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char Promote;
 
  523     typedef Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char UnsignedPromote;
 
  524     typedef Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char RealPromote;
 
  525     typedef Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char ComplexPromote;
 
  526     typedef Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char ValueType;
 
  528     typedef Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char isScalar;
 
  529     typedef Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char isIntegral;
 
  530     typedef Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char isSigned;
 
  531     typedef Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char isOrdered;
 
  532     typedef Error_NumericTraits_char_is_not_a_numeric_type__use_signed_char_or_unsigned_char isComplex;
 
  537 struct NumericTraits<bool>
 
  541     typedef unsigned int UnsignedPromote;
 
  542     typedef double RealPromote;
 
  543     typedef std::complex<RealPromote> ComplexPromote;
 
  544     typedef Type ValueType;
 
  546     typedef VigraTrueType isIntegral;
 
  547     typedef VigraTrueType isScalar;
 
  548     typedef VigraFalseType isSigned;
 
  549     typedef VigraTrueType isOrdered;
 
  550     typedef VigraFalseType isComplex;
 
  552     static bool zero() { 
return false; }
 
  553     static bool one() { 
return true; }
 
  554     static bool nonZero() { 
return true; }
 
  555     static bool min() { 
return false; }
 
  556     static bool max() { 
return true; }
 
  558 #ifdef NO_INLINE_STATIC_CONST_DEFINITION 
  559     enum { minConst = false , maxConst = 
true };
 
  561     static const bool minConst = 
false;
 
  562     static const bool maxConst = 
true;
 
  565     static Promote toPromote(
bool v) { 
return v ? 1 : 0; }
 
  566     static RealPromote toRealPromote(
bool v) { 
return v ? 1.0 : 0.0; }
 
  567     static bool fromPromote(Promote v) { 
 
  568         return (v == 0) ? 
false : 
true; 
 
  570     static bool fromRealPromote(RealPromote v) {
 
  571         return (v == 0.0) ? 
false : 
true; 
 
  577 struct NumericTraits<signed char>
 
  579     typedef signed char Type;
 
  581     typedef unsigned int UnsignedPromote;
 
  582     typedef double RealPromote;
 
  583     typedef std::complex<RealPromote> ComplexPromote;
 
  584     typedef Type ValueType;
 
  586     typedef VigraTrueType isIntegral;
 
  587     typedef VigraTrueType isScalar;
 
  588     typedef VigraTrueType isSigned;
 
  589     typedef VigraTrueType isOrdered;
 
  590     typedef VigraFalseType isComplex;
 
  592     static signed char zero() { 
return 0; }
 
  593     static signed char one() { 
return 1; }
 
  594     static signed char nonZero() { 
return 1; }
 
  595     static signed char min() { 
return SCHAR_MIN; }
 
  596     static signed char max() { 
return SCHAR_MAX; }
 
  598 #ifdef NO_INLINE_STATIC_CONST_DEFINITION 
  599     enum { minConst = SCHAR_MIN, maxConst = SCHAR_MIN };
 
  601     static const signed char minConst = SCHAR_MIN;
 
  602     static const signed char maxConst = SCHAR_MIN;
 
  605     static Promote toPromote(
signed char v) { 
return v; }
 
  606     static RealPromote toRealPromote(
signed char v) { 
return v; }
 
  607     static signed char fromPromote(Promote v) {
 
  608         return detail::clamp_integer_to_signed<Promote, signed char>(v, SCHAR_MIN, SCHAR_MAX);
 
  610     static signed char fromRealPromote(RealPromote v) {
 
  611         return detail::clamp_float_to_signed<RealPromote, signed char>(v, SCHAR_MIN, SCHAR_MAX);
 
  616 struct NumericTraits<unsigned char>
 
  618     typedef unsigned char Type;
 
  620     typedef unsigned int UnsignedPromote;
 
  621     typedef double RealPromote;
 
  622     typedef std::complex<RealPromote> ComplexPromote;
 
  623     typedef Type ValueType;
 
  625     typedef VigraTrueType isIntegral;
 
  626     typedef VigraTrueType isScalar;
 
  627     typedef VigraFalseType isSigned;
 
  628     typedef VigraTrueType isOrdered;
 
  629     typedef VigraFalseType isComplex;
 
  631     static unsigned char zero() { 
return 0; }
 
  632     static unsigned char one() { 
return 1; }
 
  633     static unsigned char nonZero() { 
return 1; }
 
  634     static unsigned char min() { 
return 0; }
 
  635     static unsigned char max() { 
return UCHAR_MAX; }
 
  637 #ifdef NO_INLINE_STATIC_CONST_DEFINITION 
  638     enum { minConst = 0, maxConst = UCHAR_MAX };
 
  640     static const unsigned char minConst = 0;
 
  641     static const unsigned char maxConst = UCHAR_MAX;
 
  644     static Promote toPromote(
unsigned char v) { 
return v; }
 
  645     static RealPromote toRealPromote(
unsigned char v) { 
return v; }
 
  646     static unsigned char fromPromote(Promote v) {
 
  647         return detail::clamp_integer_to_unsigned<Promote, unsigned char>(v, UCHAR_MAX);
 
  649     static unsigned char fromRealPromote(RealPromote v) {
 
  650         return detail::clamp_float_to_unsigned<RealPromote, unsigned char>(v, UCHAR_MAX);
 
  655 struct NumericTraits<short int>
 
  657     typedef short int Type;
 
  659     typedef unsigned int UnsignedPromote;
 
  660     typedef double RealPromote;
 
  661     typedef std::complex<RealPromote> ComplexPromote;
 
  662     typedef Type ValueType;
 
  664     typedef VigraTrueType isIntegral;
 
  665     typedef VigraTrueType isScalar;
 
  666     typedef VigraTrueType isSigned;
 
  667     typedef VigraTrueType isOrdered;
 
  668     typedef VigraFalseType isComplex;
 
  670     static short int zero() { 
return 0; }
 
  671     static short int one() { 
return 1; }
 
  672     static short int nonZero() { 
return 1; }
 
  673     static short int min() { 
return SHRT_MIN; }
 
  674     static short int max() { 
return SHRT_MAX; }
 
  676 #ifdef NO_INLINE_STATIC_CONST_DEFINITION 
  677     enum { minConst = SHRT_MIN, maxConst = SHRT_MAX };
 
  679     static const short int minConst = SHRT_MIN;
 
  680     static const short int maxConst = SHRT_MAX;
 
  683     static Promote toPromote(
short int v) { 
return v; }
 
  684     static RealPromote toRealPromote(
short int v) { 
return v; }
 
  685     static short int fromPromote(Promote v) {
 
  686         return detail::clamp_integer_to_signed<Promote, short int>(v, SHRT_MIN, SHRT_MAX);
 
  688     static short int fromRealPromote(RealPromote v) {
 
  689         return detail::clamp_float_to_signed<RealPromote, short int>(v, SHRT_MIN, SHRT_MAX);
 
  694 struct NumericTraits<short unsigned int>
 
  696     typedef short unsigned int Type;
 
  698     typedef unsigned int UnsignedPromote;
 
  699     typedef double RealPromote;
 
  700     typedef std::complex<RealPromote> ComplexPromote;
 
  701     typedef Type ValueType;
 
  703     typedef VigraTrueType isIntegral;
 
  704     typedef VigraTrueType isScalar;
 
  705     typedef VigraFalseType isSigned;
 
  706     typedef VigraTrueType isOrdered;
 
  707     typedef VigraFalseType isComplex;
 
  709     static short unsigned int zero() { 
return 0; }
 
  710     static short unsigned int one() { 
return 1; }
 
  711     static short unsigned int nonZero() { 
return 1; }
 
  712     static short unsigned int min() { 
return 0; }
 
  713     static short unsigned int max() { 
return USHRT_MAX; }
 
  715 #ifdef NO_INLINE_STATIC_CONST_DEFINITION 
  716     enum { minConst = 0, maxConst = USHRT_MAX };
 
  718     static const short unsigned int minConst = 0;
 
  719     static const short unsigned int maxConst = USHRT_MAX;
 
  722     static Promote toPromote(
short unsigned int v) { 
return v; }
 
  723     static RealPromote toRealPromote(
short unsigned int v) { 
return v; }
 
  724     static short unsigned int fromPromote(Promote v) {
 
  725         return detail::clamp_integer_to_unsigned<Promote, short unsigned int>(v, USHRT_MAX);
 
  727     static short unsigned int fromRealPromote(RealPromote v) {
 
  728         return detail::clamp_float_to_unsigned<RealPromote, short unsigned int>(v, USHRT_MAX);
 
  733 struct NumericTraits<int>
 
  737     typedef unsigned int UnsignedPromote;
 
  738     typedef double RealPromote;
 
  739     typedef std::complex<RealPromote> ComplexPromote;
 
  740     typedef Type ValueType;
 
  742     typedef VigraTrueType isIntegral;
 
  743     typedef VigraTrueType isScalar;
 
  744     typedef VigraTrueType isSigned;
 
  745     typedef VigraTrueType isOrdered;
 
  746     typedef VigraFalseType isComplex;
 
  748     static int zero() { 
return 0; }
 
  749     static int one() { 
return 1; }
 
  750     static int nonZero() { 
return 1; }
 
  751     static int min() { 
return INT_MIN; }
 
  752     static int max() { 
return INT_MAX; }
 
  754 #ifdef NO_INLINE_STATIC_CONST_DEFINITION 
  755     enum { minConst = INT_MIN, maxConst = INT_MAX };
 
  757     static const int minConst = INT_MIN;
 
  758     static const int maxConst = INT_MAX;
 
  761     static Promote toPromote(
int v) { 
return v; }
 
  762     static RealPromote toRealPromote(
int v) { 
return v; }
 
  763     static int fromPromote(Promote v) { 
return v; }
 
  764     static int fromRealPromote(RealPromote v) {
 
  765         return detail::clamp_float_to_signed<RealPromote, int>(v, INT_MIN, INT_MAX);
 
  770 struct NumericTraits<unsigned int>
 
  772     typedef unsigned int Type;
 
  773     typedef unsigned int Promote;
 
  774     typedef unsigned int UnsignedPromote;
 
  775     typedef double RealPromote;
 
  776     typedef std::complex<RealPromote> ComplexPromote;
 
  777     typedef Type ValueType;
 
  779     typedef VigraTrueType isIntegral;
 
  780     typedef VigraTrueType isScalar;
 
  781     typedef VigraFalseType isSigned;
 
  782     typedef VigraTrueType isOrdered;
 
  783     typedef VigraFalseType isComplex;
 
  785     static unsigned int zero() { 
return 0; }
 
  786     static unsigned int one() { 
return 1; }
 
  787     static unsigned int nonZero() { 
return 1; }
 
  788     static unsigned int min() { 
return 0; }
 
  789     static unsigned int max() { 
return UINT_MAX; }
 
  791 #ifdef NO_INLINE_STATIC_CONST_DEFINITION 
  792     enum { minConst = 0, maxConst = UINT_MAX };
 
  794     static const unsigned int minConst = 0;
 
  795     static const unsigned int maxConst = UINT_MAX;
 
  798     static Promote toPromote(
unsigned int v) { 
return v; }
 
  799     static RealPromote toRealPromote(
unsigned int v) { 
return v; }
 
  800     static unsigned int fromPromote(Promote v) { 
return v; }
 
  801     static unsigned int fromRealPromote(RealPromote v) {
 
  802         return detail::clamp_float_to_unsigned<RealPromote, unsigned int>(v, UINT_MAX);
 
  807 struct NumericTraits<long>
 
  810     typedef long Promote;
 
  811     typedef unsigned long UnsignedPromote;
 
  812     typedef double RealPromote;
 
  813     typedef std::complex<RealPromote> ComplexPromote;
 
  814     typedef Type ValueType;
 
  816     typedef VigraTrueType isIntegral;
 
  817     typedef VigraTrueType isScalar;
 
  818     typedef VigraTrueType isSigned;
 
  819     typedef VigraTrueType isOrdered;
 
  820     typedef VigraFalseType isComplex;
 
  822     static long zero() { 
return 0; }
 
  823     static long one() { 
return 1; }
 
  824     static long nonZero() { 
return 1; }
 
  825     static long min() { 
return LONG_MIN; }
 
  826     static long max() { 
return LONG_MAX; }
 
  828 #ifdef NO_INLINE_STATIC_CONST_DEFINITION 
  829     enum { minConst = LONG_MIN, maxConst = LONG_MAX };
 
  831     static const long minConst = LONG_MIN;
 
  832     static const long maxConst = LONG_MAX;
 
  835     static Promote toPromote(
long v) { 
return v; }
 
  836     static RealPromote toRealPromote(
long v) { 
return static_cast<RealPromote
>(v); }
 
  837     static long fromPromote(Promote v) { 
return v; }
 
  838     static long fromRealPromote(RealPromote v) {
 
  839         return detail::clamp_float_to_signed<RealPromote, long>(v, LONG_MIN, LONG_MAX);
 
  844 struct NumericTraits<unsigned long>
 
  846     typedef unsigned long Type;
 
  847     typedef unsigned long Promote;
 
  848     typedef unsigned long UnsignedPromote;
 
  849     typedef double RealPromote;
 
  850     typedef std::complex<RealPromote> ComplexPromote;
 
  851     typedef Type ValueType;
 
  853     typedef VigraTrueType isIntegral;
 
  854     typedef VigraTrueType isScalar;
 
  855     typedef VigraFalseType isSigned;
 
  856     typedef VigraTrueType isOrdered;
 
  857     typedef VigraFalseType isComplex;
 
  859     static unsigned long zero() { 
return 0; }
 
  860     static unsigned long one() { 
return 1; }
 
  861     static unsigned long nonZero() { 
return 1; }
 
  862     static unsigned long min() { 
return 0; }
 
  863     static unsigned long max() { 
return ULONG_MAX; }
 
  865 #ifdef NO_INLINE_STATIC_CONST_DEFINITION 
  866     enum { minConst = 0, maxConst = ULONG_MAX };
 
  868     static const unsigned long minConst = 0;
 
  869     static const unsigned long maxConst = ULONG_MAX;
 
  872     static Promote toPromote(
unsigned long v) { 
return v; }
 
  873     static RealPromote toRealPromote(
unsigned long v) { 
return static_cast<RealPromote
>(v); }
 
  874     static unsigned long fromPromote(Promote v) { 
return v; }
 
  875     static unsigned long fromRealPromote(RealPromote v) {
 
  876         return detail::clamp_float_to_unsigned<RealPromote, unsigned long>(v, ULONG_MAX);
 
  882 struct NumericTraits<long long>
 
  884     typedef long long Type;
 
  885     typedef long long Promote;
 
  886     typedef unsigned long long UnsignedPromote;
 
  887     typedef double RealPromote;
 
  888     typedef std::complex<RealPromote> ComplexPromote;
 
  889     typedef Type ValueType;
 
  891     typedef VigraTrueType isIntegral;
 
  892     typedef VigraTrueType isScalar;
 
  893     typedef VigraTrueType isSigned;
 
  894     typedef VigraTrueType isOrdered;
 
  895     typedef VigraFalseType isComplex;
 
  897     static long long zero() { 
return 0; }
 
  898     static long long one() { 
return 1; }
 
  899     static long long nonZero() { 
return 1; }
 
  900     static long long min() { 
return LLONG_MIN; }
 
  901     static long long max() { 
return LLONG_MAX; }
 
  903 #ifdef NO_INLINE_STATIC_CONST_DEFINITION 
  904     enum { minConst = LLONG_MIN, maxConst = LLONG_MAX };
 
  906     static const long long minConst = LLONG_MIN;
 
  907     static const long long maxConst = LLONG_MAX;
 
  910     static Promote toPromote(
long long v) { 
return v; }
 
  911     static RealPromote toRealPromote(
long long v) { 
return (RealPromote)v; }
 
  912     static long long fromPromote(Promote v) { 
return v; }
 
  913     static long long fromRealPromote(RealPromote v) {
 
  914         return detail::clamp_float_to_signed<RealPromote, long long>(v, LLONG_MIN, LLONG_MAX);
 
  919 struct NumericTraits<unsigned long long>
 
  921     typedef unsigned long long Type;
 
  922     typedef unsigned long long Promote;
 
  923     typedef unsigned long long UnsignedPromote;
 
  924     typedef double RealPromote;
 
  925     typedef std::complex<RealPromote> ComplexPromote;
 
  926     typedef Type ValueType;
 
  928     typedef VigraTrueType isIntegral;
 
  929     typedef VigraTrueType isScalar;
 
  930     typedef VigraFalseType isSigned;
 
  931     typedef VigraTrueType isOrdered;
 
  932     typedef VigraFalseType isComplex;
 
  934     static unsigned long long zero() { 
return 0; }
 
  935     static unsigned long long one() { 
return 1; }
 
  936     static unsigned long long nonZero() { 
return 1; }
 
  937     static unsigned long long min() { 
return 0; }
 
  938     static unsigned long long max() { 
return ULLONG_MAX; }
 
  940 #ifdef NO_INLINE_STATIC_CONST_DEFINITION 
  941     enum { minConst = 0, maxConst = ULLONG_MAX };
 
  943     static const unsigned long long minConst = 0;
 
  944     static const unsigned long long maxConst = ULLONG_MAX;
 
  947     static Promote toPromote(
unsigned long long v) { 
return v; }
 
  948     static RealPromote toRealPromote(
unsigned long long v) { 
return (RealPromote)v; }
 
  949     static unsigned long long fromPromote(Promote v) { 
return v; }
 
  950     static unsigned long long fromRealPromote(RealPromote v) {
 
  951         return detail::clamp_float_to_unsigned<RealPromote, unsigned long long>(v, ULLONG_MAX);
 
  957 struct NumericTraits<float>
 
  960     typedef float Promote;
 
  961     typedef float UnsignedPromote;
 
  962     typedef float RealPromote;
 
  963     typedef std::complex<RealPromote> ComplexPromote;
 
  964     typedef Type ValueType;
 
  966     typedef VigraFalseType isIntegral;
 
  967     typedef VigraTrueType isScalar;
 
  968     typedef VigraTrueType isSigned;
 
  969     typedef VigraTrueType isOrdered;
 
  970     typedef VigraFalseType isComplex;
 
  972     static float zero() { 
return 0.0; }
 
  973     static float one() { 
return 1.0; }
 
  974     static float nonZero() { 
return 1.0; }
 
  975     static float epsilon() { 
return FLT_EPSILON; }
 
  976     static float smallestPositive() { 
return FLT_MIN; }
 
  977     static float min() { 
return -FLT_MAX; }
 
  978     static float max() { 
return FLT_MAX; }
 
  980     static Promote toPromote(
float v) { 
return v; }
 
  981     static RealPromote toRealPromote(
float v) { 
return v; }
 
  982     static float fromPromote(Promote v) { 
return v; }
 
  983     static float fromRealPromote(RealPromote v) { 
return v; }
 
  987 struct NumericTraits<double>
 
  990     typedef double Promote;
 
  991     typedef double UnsignedPromote;
 
  992     typedef double RealPromote;
 
  993     typedef std::complex<RealPromote> ComplexPromote;
 
  994     typedef Type ValueType;
 
  996     typedef VigraFalseType isIntegral;
 
  997     typedef VigraTrueType isScalar;
 
  998     typedef VigraTrueType isSigned;
 
  999     typedef VigraTrueType isOrdered;
 
 1000     typedef VigraFalseType isComplex;
 
 1002     static double zero() { 
return 0.0; }
 
 1003     static double one() { 
return 1.0; }
 
 1004     static double nonZero() { 
return 1.0; }
 
 1005     static double epsilon() { 
return DBL_EPSILON; }
 
 1006     static double smallestPositive() { 
return DBL_MIN; }
 
 1007     static double min() { 
return -DBL_MAX; }
 
 1008     static double max() { 
return DBL_MAX; }
 
 1010     static Promote toPromote(
double v) { 
return v; }
 
 1011     static RealPromote toRealPromote(
double v) { 
return v; }
 
 1012     static double fromPromote(Promote v) { 
return v; }
 
 1013     static double fromRealPromote(RealPromote v) { 
return v; }
 
 1017 struct NumericTraits<long double>
 
 1019     typedef long double Type;
 
 1020     typedef long double Promote;
 
 1021     typedef long double UnsignedPromote;
 
 1022     typedef long double RealPromote;
 
 1023     typedef std::complex<RealPromote> ComplexPromote;
 
 1024     typedef Type ValueType;
 
 1026     typedef VigraFalseType isIntegral;
 
 1027     typedef VigraTrueType isScalar;
 
 1028     typedef VigraTrueType isSigned;
 
 1029     typedef VigraTrueType isOrdered;
 
 1030     typedef VigraFalseType isComplex;
 
 1032     static long double zero() { 
return 0.0; }
 
 1033     static long double one() { 
return 1.0; }
 
 1034     static long double nonZero() { 
return 1.0; }
 
 1035     static long double epsilon() { 
return LDBL_EPSILON; }
 
 1036     static long double smallestPositive() { 
return LDBL_MIN; }
 
 1037     static long double min() { 
return -LDBL_MAX; }
 
 1038     static long double max() { 
return LDBL_MAX; }
 
 1040     static Promote toPromote(
long double v) { 
return v; }
 
 1041     static RealPromote toRealPromote(
long double v) { 
return v; }
 
 1042     static long double fromPromote(Promote v) { 
return v; }
 
 1043     static long double fromRealPromote(RealPromote v) { 
return v; }
 
 1046 #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION 
 1049 struct NumericTraits<std::complex<T> >
 
 1051     typedef std::complex<T> Type;
 
 1052     typedef std::complex<typename NumericTraits<T>::Promote> Promote;
 
 1053     typedef std::complex<typename NumericTraits<T>::UnsignedPromote> UnsignedPromote;
 
 1054     typedef std::complex<typename NumericTraits<T>::RealPromote> RealPromote;
 
 1055     typedef std::complex<RealPromote> ComplexPromote;
 
 1056     typedef T ValueType;
 
 1058     typedef VigraFalseType isIntegral;
 
 1059     typedef VigraFalseType isScalar;
 
 1060     typedef typename NumericTraits<T>::isSigned isSigned;
 
 1061     typedef VigraFalseType isOrdered;
 
 1062     typedef VigraTrueType isComplex;
 
 1064     static Type zero() { 
return Type(0.0); }
 
 1065     static Type one() { 
return Type(1.0); }
 
 1066     static Type nonZero() { 
return one(); }
 
 1067     static Type epsilon() { 
return Type(NumericTraits<T>::epsilon()); }
 
 1068     static Type smallestPositive() { 
return Type(NumericTraits<T>::smallestPositive()); }
 
 1070     static Promote toPromote(Type 
const & v) { 
return v; }
 
 1071     static Type fromPromote(Promote 
const & v) { 
return v; }
 
 1072     static Type fromRealPromote(RealPromote v) { 
return Type(v); }
 
 1075 #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION 
 1084 struct SquareRootTraits
 
 1087     typedef typename NumericTraits<T>::RealPromote               SquareRootResult;
 
 1088     typedef typename NumericTraits<T>::RealPromote               SquareRootArgument;
 
 1098 struct Error_NormTraits_not_specialized_for_this_case { };
 
 1104     typedef Error_NormTraits_not_specialized_for_this_case   SquaredNormType;
 
 1105     typedef Error_NormTraits_not_specialized_for_this_case   NormType;
 
 1108 #define VIGRA_DEFINE_NORM_TRAITS(T) \ 
 1109     template <> struct NormTraits<T> { \ 
 1111         typedef NumericTraits<T>::Promote SquaredNormType; \ 
 1112         typedef T NormType; \ 
 1115 VIGRA_DEFINE_NORM_TRAITS(
bool)
 
 1116 VIGRA_DEFINE_NORM_TRAITS(
signed char)
 
 1117 VIGRA_DEFINE_NORM_TRAITS(
unsigned char)
 
 1118 VIGRA_DEFINE_NORM_TRAITS(
short)
 
 1119 VIGRA_DEFINE_NORM_TRAITS(
unsigned short)
 
 1120 VIGRA_DEFINE_NORM_TRAITS(
int)
 
 1121 VIGRA_DEFINE_NORM_TRAITS(
unsigned int)
 
 1122 VIGRA_DEFINE_NORM_TRAITS(
long)
 
 1123 VIGRA_DEFINE_NORM_TRAITS(
unsigned long)
 
 1124 VIGRA_DEFINE_NORM_TRAITS(
float)
 
 1125 VIGRA_DEFINE_NORM_TRAITS(
double)
 
 1126 VIGRA_DEFINE_NORM_TRAITS(
long double)
 
 1129 VIGRA_DEFINE_NORM_TRAITS(
long long)
 
 1130 VIGRA_DEFINE_NORM_TRAITS(
unsigned long long)
 
 1133 #undef VIGRA_DEFINE_NORM_TRAITS 
 1135 #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION 
 1138 struct NormTraits<std::complex<T> >
 
 1140     typedef std::complex<T>                                              Type;
 
 1141     typedef typename NormTraits<T>::SquaredNormType                      SquaredNormType;
 
 1142     typedef typename SquareRootTraits<SquaredNormType>::SquareRootResult NormType;
 
 1145 #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION 
 1155 template <
class T, 
class U>
 
 1161     typedef typename SizeToType<sizeof(*typeToSize(t() + u()))>::result Promote;
 
 1162     static Promote toPromote(T t) { 
return Promote(t); }
 
 1163     static Promote toPromote(U u) { 
return Promote(u); }
 
 1168 struct PromoteType<T, T>
 
 1172     typedef typename SizeToType<sizeof(*typeToSize(t() + t()))>::result Promote;
 
 1173     static Promote toPromote(T t) { 
return Promote(t); }
 
 1178 struct Error_PromoteTraits_not_specialized_for_this_case { };
 
 1180 template<
class A, 
class B>
 
 1181 struct PromoteTraits
 
 1183     typedef Error_PromoteTraits_not_specialized_for_this_case Promote;
 
 1186 #include "promote_traits.hxx" 
 1188 #ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION 
 1191 struct PromoteTraits<std::complex<T>, std::complex<T> >
 
 1193     typedef std::complex<typename PromoteTraits<T, T>::Promote> Promote;
 
 1194     static Promote toPromote(std::complex<T> 
const & v) { 
return v; }
 
 1197 template <
class T1, 
class T2>
 
 1198 struct PromoteTraits<std::complex<T1>, std::complex<T2> >
 
 1200     typedef std::complex<typename PromoteTraits<T1, T2>::Promote> Promote;
 
 1201     static Promote toPromote(std::complex<T1> 
const & v) { 
return v; }
 
 1202     static Promote toPromote(std::complex<T2> 
const & v) { 
return v; }
 
 1205 template <
class T1, 
class T2>
 
 1206 struct PromoteTraits<std::complex<T1>, T2 >
 
 1208     typedef std::complex<typename PromoteTraits<T1, T2>::Promote> Promote;
 
 1209     static Promote toPromote(std::complex<T1> 
const & v) { 
return v; }
 
 1210     static Promote toPromote(T2 
const & v) { 
return Promote(v); }
 
 1213 template <
class T1, 
class T2>
 
 1214 struct PromoteTraits<T1, std::complex<T2> >
 
 1216     typedef std::complex<typename PromoteTraits<T1, T2>::Promote> Promote;
 
 1217     static Promote toPromote(T1 
const & v) { 
return Promote(v); }
 
 1218     static Promote toPromote(std::complex<T2> 
const & v) { 
return v; }
 
 1226 struct RequiresExplicitCast {
 
 1228     static U 
const & cast(U 
const & v)
 
 1232 #if !defined(_MSC_VER) || _MSC_VER >= 1300 
 1233 #  define VIGRA_SPECIALIZED_CAST(type) \ 
 1235     struct RequiresExplicitCast<type> { \ 
 1236         static type cast(float v) \ 
 1237             { return NumericTraits<type>::fromRealPromote(v); } \ 
 1238         static type cast(double v) \ 
 1239             { return NumericTraits<type>::fromRealPromote(v); } \ 
 1240         static type cast(type v) \ 
 1242         template <class U> \ 
 1243         static type cast(U v) \ 
 1244             { return static_cast<type>(v); } \ 
 1248 #  define VIGRA_SPECIALIZED_CAST(type) \ 
 1250     struct RequiresExplicitCast<type> { \ 
 1251         static type cast(float v) \ 
 1252             { return NumericTraits<type>::fromRealPromote(v); } \ 
 1253         static type cast(double v) \ 
 1254             { return NumericTraits<type>::fromRealPromote(v); } \ 
 1255         static type cast(signed char v) \ 
 1257         static type cast(unsigned char v) \ 
 1259         static type cast(short v) \ 
 1261         static type cast(unsigned short v) \ 
 1263         static type cast(int v) \ 
 1265         static type cast(unsigned int v) \ 
 1267         static type cast(long v) \ 
 1269         static type cast(unsigned long v) \ 
 1275 VIGRA_SPECIALIZED_CAST(
signed char)
 
 1276 VIGRA_SPECIALIZED_CAST(
unsigned char)
 
 1277 VIGRA_SPECIALIZED_CAST(
short)
 
 1278 VIGRA_SPECIALIZED_CAST(
unsigned short)
 
 1279 VIGRA_SPECIALIZED_CAST(
int)
 
 1280 VIGRA_SPECIALIZED_CAST(
unsigned int)
 
 1281 VIGRA_SPECIALIZED_CAST(
long)
 
 1282 VIGRA_SPECIALIZED_CAST(
unsigned long)
 
 1285 struct RequiresExplicitCast<
bool> {
 
 1287     static bool cast(U v)
 
 1288     { 
return v == NumericTraits<U>::zero()
 
 1294 struct RequiresExplicitCast<float> {
 
 1295     static float cast(
int v)
 
 1296         { 
return (
float)v; }
 
 1298     static float cast(
unsigned int v)
 
 1299         { 
return (
float)v; }
 
 1301     static float cast(
long v)
 
 1302         { 
return (
float)v; }
 
 1304     static float cast(
unsigned long v)
 
 1305         { 
return (
float)v; }
 
 1307     static float cast(
long long v)
 
 1308         { 
return (
float)v; }
 
 1310     static float cast(
unsigned long long v)
 
 1311         { 
return (
float)v; }
 
 1313     static float cast(
double v)
 
 1314         { 
return (
float)v; }
 
 1316     static float cast(
long double v)
 
 1317         { 
return (
float)v; }
 
 1325 struct RequiresExplicitCast<double> {
 
 1326     static double cast(
Int64 v)
 
 1327         { 
return (
double)v; }
 
 1329     static double cast(
UInt64 v)
 
 1330         { 
return (
double)v; }
 
 1337 #undef VIGRA_SPECIALIZED_CAST 
 1345 #endif // VIGRA_NUMERICTRAITS_HXX 
detail::SelectIntegerType< 64, detail::SignedIntTypes >::type Int64
64-bit signed int 
Definition: sized_int.hxx:177
detail::SelectIntegerType< 64, detail::UnsignedIntTypes >::type UInt64
64-bit unsigned int 
Definition: sized_int.hxx:185