- int max_tree42 = npair_top * pow(2.0, nrows + 1);
- if (ncol_top > npair_top * 2) {
- int delta = ncol_bot - max_tree42;
+ int max_tree42 = 0;
+ // number of rows needed to reduce ncol_bot to ncol_top using simple 4->2 "tree"
+#ifdef WIN32
+ //<cmath> of the MSVC doesn't contain log2
+ int nrows_tree42 = int( log( (double)(ncol_bot / ncol_top) )/log((double)2) ); // needed to avoid overflow at pow(2)
+#else
+ int nrows_tree42 = int( log2( ncol_bot / ncol_top )); // needed to avoid overflow at pow(2)
+#endif
+
+ if (ncol_top > npair_top * 2 && nrows_tree42 < nrows) {
+ max_tree42 = npair_top * pow(2.0, nrows + 1);
+ int delta = ncol_bot - int( max_tree42 );