https://bugs.documentfoundation.org/show_bug.cgi?id=96821

--- Comment #8 from [email protected] ---
C1=1024*1024*1024*1024*1024*4

IEEE-758 [for binary formats] doesn't do decimal digits.  It does binary
digits.  C1 requires *one* binary digit of mantissa.

On page 8 of the 2008 version of the standard you will find details of
the "binary64" format that corresponds to the C "double" type on all
modern hardware.  53 bits for mantissa, 11 bits for exponent, and one
sign bit.  That adds to 65 bits, but the most significant bit for the
mantissa isn't stored as it is always 1.

So C1 is perfectly representable as is B1 (=C1+1), although B1 is
just at the limit of what can be represented.  But look what happens
if someone tries to round to nearest integer using this code with x=B1:

   x = std::floor (x + 0.5);   // WRONG

Adding 0.5 to x produces a number that is precisely midway between two
representable numbers, which are x and x+1.  IEEE-758 specifies to round
according to the current rounding mode which, typically, is round-to-even. 
Therefore the rounding result will be x+1.  std::floor will not change
that.  The intent with the above code was to add 0.5 and have std::floor
throw away the decimal part.  That works fine for smaller numbers, but
not for the magnitude of B1.  It also works for numbers above 2*B1 because
they are all even, so adding 0.5 and rounding will leave the number
unchanged.

You might want to take a look at "man round", but note that it may not do
the right thing for negative numbers.

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs

Reply via email to