« Previous | Next » 

Revision e41b509d

IDe41b509d68afb1f329c8558b6edfe2fcbac88e66

Added by Paolo Bonzini about 10 years ago

qapi: Refine human printing of sizes

This fixes several bugs or shortcomings of the previous pretty-printer.
In particular:

  • use PRIu64 instead of casting to long long
  • the exact value is included too
  • the correct unit of measure (MiB, GiB, etc.) is used. PiB and EiB
    are added too.
  • due to an off-by-one error, 512*2^30 was printed as 0.500MiB rather than
    512MiB. floor(log2(val)) is equal to 63 - clz(val), while the code used 64.
  • The desired specification is %g rather than %f, which always uses three
    decimals in the current code. However %g would switch to scientific
    notation when the integer part is >= 1000 (e.g. 1000*2^30). To keep the
    code simple, switch to the higher power when the integer part is >= 1000;
    overflow is avoided by using frexp instead of clz.

Suggested-by: Eric Blake <>
Reviewed-by: Igor Mammedov <>
Reviewed-by: Eric Blake <>
Signed-off-by: Paolo Bonzini <>
Signed-off-by: Andreas Färber <>

Files

  • added
  • modified
  • copied
  • renamed
  • deleted

View differences