diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp index e2a135c..f50b74d 100644 --- a/include/mcl/fp.hpp +++ b/include/mcl/fp.hpp @@ -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(&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 { diff --git a/include/mcl/op.hpp b/include/mcl/op.hpp index 2f99c42..7b2ec14 100644 --- a/include/mcl/op.hpp +++ b/include/mcl/op.hpp @@ -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)) ? "" : " "; diff --git a/src/fp.cpp b/src/fp.cpp index 76dada3..c99a3fe 100644 --- a/src/fp.cpp +++ b/src/fp.cpp @@ -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;