Skip to content

Commit b7b7059

Browse files
committed
Round correctly
1 parent 58a744b commit b7b7059

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

highs/ipm/hipo/ipm/Model.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,14 @@ void Model::print(const LogHighs& log) const {
398398

399399
static double roundToPowerOf2(double d) {
400400
int exp; // int, not Int
401-
std::frexp(d, &exp);
401+
402+
// d = x * 2^exp, d\in[0.5,1)
403+
auto x = std::frexp(d, &exp);
404+
405+
// d is already exact power of 2
406+
if (x == 0.5) return d;
407+
408+
// return 1*2^exp
402409
return std::ldexp(1.0, exp);
403410
}
404411

0 commit comments

Comments
 (0)