Boost logo

Boost Users :

Subject: [Boost-users] boost::units::information::byte_base_unit off by a factor of 8
From: Simon Doppler (dopsi+boost_at_[hidden])
Date: 2018-03-21 09:01:30


I am trying to build a program that will display file sizes in human
readable form. The file size is in bytes and I am using boost::units
to convert the bytes to a binary prefixed unit.

Using the example code found here[1], I build a small program
to test the library and the output is off by a factor of 8:

    boost::units::quantity<boost::units::information::byte_base_unit::unit_type> b = 2048. * boost::units::information::byte_base_unit::unit_type();
    std::cout << boost::units::engineering_prefix << b << std::endl; // expected 2.048 kb
    std::cout << boost::units::symbol_format << boost::units::binary_prefix << b << std::endl; // "expected 2 Kib"

but the output on stdout is:

16.384 kb
16 Kib

which is 8 times the expected result. The whole example code
can be found here[2].

I have tested this code both on Archlinux (boost 1.66.0) as well
as Ubuntu Xenial Server (libboost-dev 1.58.0.1ubuntu1).

Do you have any idea on how to get the correct output (other
than divide the number of bytes by 8 on the input) ?

Best regards

Simon Doppler

[1] http://www.boost.org/doc/libs/1_65_0/doc/html/boost_units/Examples.html#boost_units.Examples.autoscale
[2] https://dopsi.ch/tmp/main.cpp



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net