Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::units::information::byte_base_unit off by a factor of 8
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2018-03-21 18:28:34


AMDG

On 03/21/2018 03:01 AM, Simon Doppler via Boost-users wrote:
> 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].
>

The output is "correct" in some sense. The problem is
that the output code is printing the value in terms
of bits rather than bytes (note that it uses 'b' instead
of 'B'). I'll see if I can solve this, but the
formatting code is already pretty messy.

> 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) ?
>

In Christ,
Steven Watanabe


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