Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
mie::VsintT< V > Class Template Reference

#include <zm.h>

Inheritance diagram for mie::VsintT< V >:
Collaboration diagram for mie::VsintT< V >:

Public Types

typedef V::value_type value_type
 

Public Member Functions

 VsintT (int x=0)
 
 VsintT (const std::string &str)
 
 VsintT (const V &x)
 
void set (value_type x)
 
void set (int64_t x)
 
void set (const V &x)
 
void set (const uint64_t *ptr, size_t size)
 
const Vget () const
 
Vget ()
 
void clear ()
 
std::string toString (int base=10) const
 
void set (const std::string &str, int base=10)
 
void fromStr (const std::string &str, int base=10)
 
std::string toStr (int base=10)
 
size_t size () const
 
bool isZero () const
 
bool isNegative () const
 
V abs () const
 
VsintT operator<< (size_t n) const
 
VsintToperator<<= (size_t n)
 
- Public Member Functions inherited from mie::local::addsubmul< VsintT< V >, local::comparable< VsintT< V >, local::dividable< VsintT< V >, local::hasNegative< VsintT< V >, local::shiftable< VsintT< V > > > > > >
MIE_FORCE_INLINE VsintT< V > & operator+= (const N &rhs)
 
MIE_FORCE_INLINE VsintT< V > & operator-= (const VsintT< V > &rhs)
 
MIE_FORCE_INLINE VsintT< V > & operator*= (const VsintT< V > &rhs)
 
- Public Member Functions inherited from mie::local::dividable< VsintT< V >, local::hasNegative< VsintT< V >, local::shiftable< VsintT< V > > > >
MIE_FORCE_INLINE VsintT< V > & operator/= (const VsintT< V > &rhs)
 
MIE_FORCE_INLINE VsintT< V > & operator%= (const VsintT< V > &rhs)
 
- Public Member Functions inherited from mie::local::hasNegative< VsintT< V >, local::shiftable< VsintT< V > > >
MIE_FORCE_INLINE VsintT< Voperator- () const
 
- Public Member Functions inherited from mie::local::shiftable< VsintT< V > >
MIE_FORCE_INLINE VsintT< Voperator<< (size_t n) const
 
MIE_FORCE_INLINE VsintT< Voperator>> (size_t n) const
 
MIE_FORCE_INLINE VsintT< V > & operator<<= (size_t n)
 
MIE_FORCE_INLINE VsintT< V > & operator>>= (size_t n)
 

Static Public Member Functions

static int compare (const VsintT &x, const VsintT &y)
 
static void add (VsintT &out, const VsintT &x, const VsintT &y)
 
static void sub (VsintT &out, const VsintT &x, const VsintT &y)
 
static void mul (VsintT &out, const VsintT &x, const VsintT &y)
 
static bool div (VsintT *q, VsintT &r, const VsintT &x, const VsintT &y)
 
static void neg (VsintT &out, const VsintT &x)
 
static void shl (VsintT &out, const VsintT &x, size_t n)
 
static void shr (VsintT &out, const VsintT &x, size_t n)
 
static void absolute (V &out, const VsintT &in)
 

Friends

std::ostream & operator<< (std::ostream &os, const VsintT &x)
 
std::istream & operator>> (std::istream &is, VsintT &x)
 

Detailed Description

template<class V>
class mie::VsintT< V >

Definition at line 959 of file zm.h.

Member Typedef Documentation

◆ value_type

template<class V >
V::value_type mie::VsintT< V >::value_type

Definition at line 967 of file zm.h.

Constructor & Destructor Documentation

◆ VsintT() [1/3]

template<class V >
mie::VsintT< V >::VsintT ( int x = 0)
inline

Definition at line 968 of file zm.h.

969 : v_(::abs(x))
970 , isNeg_(x < 0)
971 {
972 }
V abs() const
Definition zm.h:1149

◆ VsintT() [2/3]

template<class V >
mie::VsintT< V >::VsintT ( const std::string & str)
inlineexplicit

Definition at line 973 of file zm.h.

974 {
975 set(str);
976 }
bool set

◆ VsintT() [3/3]

template<class V >
mie::VsintT< V >::VsintT ( const V & x)
inline

Definition at line 977 of file zm.h.

978 : v_(x)
979 , isNeg_(false)
980 {
981 }

Member Function Documentation

◆ abs()

template<class V >
V mie::VsintT< V >::abs ( ) const
inline

Definition at line 1149 of file zm.h.

1149{ V x; absolute(x, *this); return x; }
static void absolute(V &out, const VsintT &in)
Definition zm.h:1144
Definition test_zm.cpp:19
Here is the call graph for this function:
Here is the caller graph for this function:

◆ absolute()

template<class V >
static void mie::VsintT< V >::absolute ( V & out,
const VsintT< V > & in )
inlinestatic

Definition at line 1144 of file zm.h.

1145 {
1146 out = in.get();
1147 }
Here is the caller graph for this function:

◆ add()

template<class V >
static void mie::VsintT< V >::add ( VsintT< V > & out,
const VsintT< V > & x,
const VsintT< V > & y )
inlinestatic

Definition at line 1033 of file zm.h.

1034 {
1035 if ((x.isNeg_ ^ y.isNeg_) == 0) {
1036 // same sign
1037 V::add(out.v_, x.v_, y.v_);
1038 out.isNeg_ = x.isNeg_;
1039 return;
1040 }
1041 int r = V::compare(x.v_, y.v_);
1042 if (r >= 0) {
1043 V::sub(out.v_, x.v_, y.v_);
1044 out.isNeg_ = x.isNeg_;
1045 } else {
1046 V::sub(out.v_, y.v_, x.v_);
1047 out.isNeg_ = y.isNeg_;
1048 }
1049 }
const mie::Vuint & r
Definition bn.cpp:28
uint64_t y
Definition sha3.cpp:34

◆ clear()

template<class V >
void mie::VsintT< V >::clear ( )
inline

Definition at line 999 of file zm.h.

999{ v_.set((value_type)0); isNeg_ = false; }
V::value_type value_type
Definition zm.h:967

◆ compare()

template<class V >
static int mie::VsintT< V >::compare ( const VsintT< V > & x,
const VsintT< V > & y )
inlinestatic

Definition at line 1020 of file zm.h.

1021 {
1022 if (x.isNeg_ ^ y.isNeg_) {
1023 if (x.isZero() && y.isZero()) return 0;
1024 return x.isNeg_ ? -1 : 1;
1025 } else {
1026 // same sign
1027 return V::compare(x.v_, y.v_) * (x.isNeg_ ? -1 : 1);
1028 }
1029 }
Here is the call graph for this function:

◆ div()

template<class V >
static bool mie::VsintT< V >::div ( VsintT< V > * q,
VsintT< V > & r,
const VsintT< V > & x,
const VsintT< V > & y )
inlinestatic

Definition at line 1073 of file zm.h.

1074 {
1075#if 1
1076 // like Python
1077 // 13 / -5 = -3 ... -2
1078 // -13 / 5 = -3 ... 2
1079 // -13 / -5 = 2 ... -3
1080 V yy = y.v_;
1081 bool ret = V::div(q ? &(q->v_) : 0, r.v_, x.v_, y.v_);
1082 if (!ret) return false;
1083 bool qsign = x.isNeg_ ^ y.isNeg_;
1084 if (r.v_.isZero()) {
1085 r.isNeg_ = false;
1086 } else {
1087 if (qsign) {
1088 if (q) {
1089 q->v_ += 1;
1090 }
1091 r.v_ = yy - r.v_;
1092 }
1093 r.isNeg_ = y.isNeg_;
1094 }
1095 if (q) q->isNeg_ = qsign;
1096 return true;
1097#else
1098 // 13 / -5 = -2 ... 3
1099 // -13 / 5 = -2 ... -3
1100 // -13 / -5 = 2 ... -3
1101 bool ret = V::div(q ? &(q->v_) : 0, r.v_, x.v_, y.v_);
1102 bool qsign = x.isNeg_ ^ y.isNeg_;
1103 r.isNeg_ = x.isNeg_;
1104 if (q) q->isNeg_ = qsign;
1105 return ret;
1106#endif
1107 }
bool isZero() const
Definition zm.h:521
CK_RV ret
Here is the call graph for this function:

◆ fromStr()

template<class V >
void mie::VsintT< V >::fromStr ( const std::string & str,
int base = 10 )
inline

Definition at line 1015 of file zm.h.

1016 {
1017 set(str, base);
1018 }

◆ get() [1/2]

template<class V >
V & mie::VsintT< V >::get ( )
inline

Definition at line 998 of file zm.h.

998{ return v_; }

◆ get() [2/2]

template<class V >
const V & mie::VsintT< V >::get ( ) const
inline

Definition at line 997 of file zm.h.

997{ return v_; }

◆ isNegative()

template<class V >
bool mie::VsintT< V >::isNegative ( ) const
inline

Definition at line 1032 of file zm.h.

1032{ return isNeg_ && !isZero(); }
bool isZero() const
Definition zm.h:1031
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isZero()

template<class V >
bool mie::VsintT< V >::isZero ( ) const
inline

Definition at line 1031 of file zm.h.

1031{ return v_.isZero(); }
Here is the caller graph for this function:

◆ mul()

template<class V >
static void mie::VsintT< V >::mul ( VsintT< V > & out,
const VsintT< V > & x,
const VsintT< V > & y )
inlinestatic

Definition at line 1068 of file zm.h.

1069 {
1070 V::mul(out.v_, x.v_, y.v_);
1071 out.isNeg_ = x.isNeg_ ^ y.isNeg_;
1072 }

◆ neg()

template<class V >
static void mie::VsintT< V >::neg ( VsintT< V > & out,
const VsintT< V > & x )
inlinestatic

Definition at line 1108 of file zm.h.

1109 {
1110 out.v_ = x.v_;
1111 out.isNeg_ = !x.isNeg_;
1112 }

◆ operator<<()

template<class V >
VsintT mie::VsintT< V >::operator<< ( size_t n) const
inline

Definition at line 1150 of file zm.h.

1151 {
1152 VsintT out; shl(out, *this, n); return out;
1153 }
VsintT(int x=0)
Definition zm.h:968
static void shl(VsintT &out, const VsintT &x, size_t n)
Definition zm.h:1125
Here is the call graph for this function:

◆ operator<<=()

template<class V >
VsintT & mie::VsintT< V >::operator<<= ( size_t n)
inline

Definition at line 1154 of file zm.h.

1155 {
1156 shl(*this, *this, n); return *this;
1157 }
Here is the call graph for this function:

◆ set() [1/5]

template<class V >
void mie::VsintT< V >::set ( const std::string & str,
int base = 10 )
inline

Definition at line 1005 of file zm.h.

1006 {
1007 isNeg_ = false;
1008 if (str.size() > 0 && str[0] == '-') {
1009 isNeg_ = true;
1010 v_.set(&str[1], base);
1011 } else {
1012 v_.set(str, base);
1013 }
1014 }
return str
Definition CLI11.hpp:1359

◆ set() [2/5]

template<class V >
void mie::VsintT< V >::set ( const uint64_t * ptr,
size_t size )
inline

Definition at line 996 of file zm.h.

996{ v_.set(ptr, size); }
size_t size() const
Definition zm.h:1030
Here is the call graph for this function:

◆ set() [3/5]

template<class V >
void mie::VsintT< V >::set ( const V & x)
inline

Definition at line 991 of file zm.h.

992 {
993 v_ = x;
994 isNeg_ = false;
995 }

◆ set() [4/5]

template<class V >
void mie::VsintT< V >::set ( int64_t x)
inline

Definition at line 986 of file zm.h.

987 {
988 isNeg_ = x < 0;
989 v_.set(isNeg_ ? -x : x);
990 }

◆ set() [5/5]

template<class V >
void mie::VsintT< V >::set ( value_type x)
inline

Definition at line 982 of file zm.h.

983 {
984 v_.set(x);
985 }
Here is the caller graph for this function:

◆ shl()

template<class V >
static void mie::VsintT< V >::shl ( VsintT< V > & out,
const VsintT< V > & x,
size_t n )
inlinestatic

Definition at line 1125 of file zm.h.

1126 {
1127 V::shl(out.v_, x.v_, n);
1128 out.isNeg_ = x.isNeg_;
1129 }
Here is the caller graph for this function:

◆ shr()

template<class V >
static void mie::VsintT< V >::shr ( VsintT< V > & out,
const VsintT< V > & x,
size_t n )
inlinestatic

Definition at line 1130 of file zm.h.

1131 {
1132 if (x.isZero()) {
1133 out.clear();
1134 return;
1135 }
1136 if (x.isNeg_) {
1137 local::errExit("shr can't deal with negative value");
1138 } else {
1139 V::shr(out.v_, x.v_, n);
1140 out.isNeg_ = false;
1141 }
1142 }
Here is the call graph for this function:

◆ size()

template<class V >
size_t mie::VsintT< V >::size ( ) const
inline

Definition at line 1030 of file zm.h.

1030{ return v_.size(); }
Here is the caller graph for this function:

◆ sub()

template<class V >
static void mie::VsintT< V >::sub ( VsintT< V > & out,
const VsintT< V > & x,
const VsintT< V > & y )
inlinestatic

Definition at line 1050 of file zm.h.

1051 {
1052 if (x.isNeg_ ^ y.isNeg_) {
1053 // different sign
1054 V::add(out.v_, x.v_, y.v_);
1055 out.isNeg_ = x.isNeg_;
1056 return;
1057 }
1058 // same sign
1059 int r = V::compare(x.v_, y.v_);
1060 if (r >= 0) {
1061 V::sub(out.v_, x.v_, y.v_);
1062 out.isNeg_ = x.isNeg_;
1063 } else {
1064 V::sub(out.v_, y.v_, x.v_);
1065 out.isNeg_ = !y.isNeg_;
1066 }
1067 }

◆ toStr()

template<class V >
std::string mie::VsintT< V >::toStr ( int base = 10)
inline

Definition at line 1019 of file zm.h.

1019{ return toString(base); }
std::string toString(int base=10) const
Definition zm.h:1000
Here is the call graph for this function:

◆ toString()

template<class V >
std::string mie::VsintT< V >::toString ( int base = 10) const
inline

Definition at line 1000 of file zm.h.

1001 {
1002 if (isNeg_) return "-" + v_.toString(base);
1003 return v_.toString(base);
1004 }
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

template<class V >
std::ostream & operator<< ( std::ostream & os,
const VsintT< V > & x )
friend

Definition at line 1113 of file zm.h.

1114 {
1115 if (x.isNeg_) os << "-";
1116 return os << x.v_;
1117 }
os_t os

◆ operator>>

template<class V >
std::istream & operator>> ( std::istream & is,
VsintT< V > & x )
friend

Definition at line 1118 of file zm.h.

1119 {
1120 std::string str;
1121 local::getDigits(is, str, true);
1122 x.set(str);
1123 return is;
1124 }

The documentation for this class was generated from the following file: