fix roundup of bitSize

dev
MITSUNARI Shigeo 8 years ago
parent 74620cb7a4
commit e46f2c2ab7
  1. 10
      include/mcl/fp.hpp
  2. 6
      src/gen.cpp
  3. 2
      test/fp_test.cpp

@ -105,6 +105,7 @@ public:
const Unit *getUnit() const { return v_; }
static inline size_t getUnitSize() { return op_.N; }
static inline size_t getBitSize() { return op_.bitSize; }
static inline size_t getByteSize() { return (op_.bitSize + 7) / 8; }
static inline const fp::Op& getOp() { return op_; }
void dump() const
{
@ -221,7 +222,7 @@ public:
void setStr(const std::string& str, int ioMode = 0)
{
if (ioMode & (IoArray | IoArrayRaw)) {
const size_t n = getBitSize() / 8;
const size_t n = getByteSize();
if (str.size() != n) throw cybozu::Exception("FpT:setStr:bad size") << str.size() << n << ioMode;
if (ioMode & IoArrayRaw) {
memcpy(v_, str.c_str(), n);
@ -289,15 +290,16 @@ public:
}
void getStr(std::string& str, int ioMode = 10) const
{
const size_t n = getByteSize();
if (ioMode & IoArrayRaw) {
str.resize(getBitSize() / 8);
str.resize(n);
memcpy(&str[0], v_, str.size());
return;
}
fp::Block b;
getBlock(b);
if (ioMode & IoArray) {
str.resize(getBitSize() / 8);
str.resize(n);
memcpy(&str[0], b.p, str.size());
return;
}
@ -380,7 +382,7 @@ public:
int ioMode = fp::detectIoMode(getIoMode(), is);
std::string str;
if (ioMode & (IoArray | IoArrayRaw)) {
str.resize(getBitSize() / 8);
str.resize(getByteSize());
is.read(&str[0], str.size());
} else {
is >> str;

@ -796,9 +796,9 @@ struct Code : public mcl::Generator {
{
this->privateFuncList = &privateFuncList;
gen_once();
uint32_t end = ((maxBitSize + unit - 1) / unit) * unit;
for (uint32_t i = 64; i <= end; i += unit) {
setBit(i);
uint32_t end = ((maxBitSize + unit - 1) / unit);
for (uint32_t n = 1; n <= end; n++) {
setBit(n * unit);
gen_all();
gen_addsub();
gen_mul();

@ -176,7 +176,7 @@ void ioModeTest()
}
std::stringstream ss;
ss << x;
CYBOZU_TEST_EQUAL(ss.str().size(), Fp::getBitSize() / 8);
CYBOZU_TEST_EQUAL(ss.str().size(), Fp::getByteSize());
Fp y;
ss >> y;
CYBOZU_TEST_EQUAL(x, y);

Loading…
Cancel
Save