Changeset de65624 in mainline


Ignore:
Timestamp:
2019-10-08T12:04:16Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a163d10
Parents:
cf9a1e2
git-author:
Jiri Svoboda <jiri@…> (2019-10-09 06:04:09)
git-committer:
Jiri Svoboda <jiri@…> (2019-10-08 12:04:16)
Message:

Fix too many integer digits when rounding capacity up

Apparently, capacity_format test could never have passed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/capa.c

    rcf9a1e2 rde65624  
    153153        assert(rc == EOK);
    154154
     155        /* Change units until we have no more than scapa_max_idig integer digits */
    155156        while (capa->m / div >= maxv) {
    156157                ++capa->cunit;
     
    170171                assert(rc == EOK);
    171172
     173                /* Division with rounding */
    172174                capa->m = (capa->m + (div / 2)) / div;
    173175                capa->dp -= rdig;
     176        }
     177
     178        /*
     179         * If we rounded up from something like 999.95 to 1000.0,, we still
     180         * have more than scapa_max_idig integer digits and need to change
     181         * units once more.
     182         */
     183        rc = ipow10_u64(capa->dp, &div);
     184        assert(rc == EOK);
     185
     186        if (capa->m / div >= 1000) {
     187                ++capa->cunit;
     188                capa->dp += 3;
     189
     190                /*
     191                 * We now have one more significant digit than we want
     192                 * so round to one less digits
     193                 */
     194                capa->m = (capa->m + 5) / 10;
     195                --capa->dp;
    174196        }
    175197}
     
    202224                ret = asprintf(rstr, "%" PRIu64 " %s", ipart, sunit);
    203225        }
     226
    204227        if (ret < 0)
    205228                return ENOMEM;
Note: See TracChangeset for help on using the changeset viewer.