Fix rounding of negative numbers (#760709)
Utils::round() was doing +0.5 then truncate. Correct for positive values. Wrong for negative values. E.G. Utils::round(-1.4) = trunc(-1.4 + 0.5) = trunc(-0.9) = 0 Round of -1.4 is definitely not 0. Fix this for negative values by subtracting 0.5 then truncating. Reference: How can I convert a floating-point value to an integer in C? https://www.cs.tut.fi/~jkorpela/round.html Bug 760709 - Add progress bars to XFS and EXT2/3/4 file system specific copy methods
This commit is contained in:
parent
af0ed90d49
commit
7049a8bc44
|
@ -44,7 +44,13 @@ const Glib::ustring DEV_MAPPER_PATH = "/dev/mapper/";
|
|||
|
||||
Sector Utils::round( double double_value )
|
||||
{
|
||||
return static_cast<Sector>( double_value + 0.5 ) ;
|
||||
// Reference:
|
||||
// How can I convert a floating-point value to an integer in C?
|
||||
// https://www.cs.tut.fi/~jkorpela/round.html
|
||||
if ( double_value >= 0.0 )
|
||||
return static_cast<Sector>( double_value + 0.5 );
|
||||
else
|
||||
return static_cast<Sector>( double_value - 0.5 );
|
||||
}
|
||||
|
||||
Gtk::Label * Utils::mk_label( const Glib::ustring & text
|
||||
|
|
Loading…
Reference in New Issue