change api of arrayToStr

dev
MITSUNARI Shigeo 8 years ago
parent 5af8df80f8
commit ce5f10297e
  1. 6
      include/mcl/fp.hpp
  2. 3
      include/mcl/op.hpp
  3. 8
      src/fp.cpp

@ -36,8 +36,6 @@ struct ZnTag;
namespace fp {
void arrayToStr(std::string& str, const Unit *x, size_t n, int base, bool withPrefix);
// copy src to dst as little endian
void copyUnitToByteAsLE(uint8_t *dst, const Unit *src, size_t byteSize);
// copy src to dst as little endian
@ -275,8 +273,8 @@ public:
fp::copyUnitToByteAsLE(reinterpret_cast<uint8_t*>(&str[0]), p, str.size());
return;
}
// use low [1-4]-bit ioMode for base
fp::arrayToStr(str, b.p, b.n, ioMode & 30, (ioMode & IoPrefix) != 0);
// use low 5-bit ioMode for base
fp::arrayToStr(str, b.p, b.n, ioMode & 31);
}
std::string getStr(int ioMode = 0) const
{

@ -291,9 +291,12 @@ private:
/*
read data from is according to ioMode,
and set x[0, n) with abs(buf[0, bufSize/sizeof(Unit)))
@note byteSize is not num of Unit
*/
void streamToArray(bool *pIsMinus, Unit *x, size_t byteSize, std::istream& is, int ioMode);
void arrayToStr(std::string& str, const Unit *x, size_t n, int ioMode);
inline const char* getIoSeparator(int ioMode)
{
return (ioMode & (IoArray | IoArrayRaw | IoTight)) ? "" : " ";

@ -458,8 +458,10 @@ void Op::init(const std::string& mstr, size_t maxBitSize, Mode mode)
sq.set(mp);
}
void arrayToStr(std::string& str, const Unit *x, size_t n, int base, bool withPrefix)
void arrayToStr(std::string& str, const Unit *x, size_t n, int ioMode)
{
int base = ioMode & ~IoPrefix;
bool withPrefix = ioMode & IoPrefix;
switch (base) {
case 0:
case 10:
@ -592,7 +594,7 @@ uint64_t getUint64(bool *pb, const fp::Block& b)
}
if (!pb) {
std::string str;
arrayToStr(str, b.p, b.n, 10, false);
arrayToStr(str, b.p, b.n, 10);
throw cybozu::Exception("fp::getUint64:large value") << str;
}
*pb = false;
@ -631,7 +633,7 @@ int64_t getInt64(bool *pb, fp::Block& b, const fp::Op& op)
}
if (!pb) {
std::string str;
arrayToStr(str, b.p, b.n, 10, false);
arrayToStr(str, b.p, b.n, 10);
throw cybozu::Exception("fp::getInt64:large value") << str << isNegative;
}
*pb = false;

Loading…
Cancel
Save