* Jarkko Hietaniemi <perlbug-followup@perl.org> [2015-11-07 23:45]:

Show quoted text> Note that this may be argued at least two ways:
>
> (1) if one specifies, say, 0x8, as the last hex digit, one may argue
> that one still specifies all the four bits, not just the top one.
> (2) or one may argue that one only specified the top bit.
>
> The code has so far been choosing the interpretation (1), but maybe
> the (2) makes more sense, because otherwise one may never specify all
> the 53 bits using the hexdigits, which is unfair the the very common
> case. (One could only specify up to 52 bits, using 13 hexdigits.) And
> hexfp is all about being able to specify the fp down to the last bit.

To the extent that my mathematical reasoning will carry me, there is no
practical loss of precision from losing trailing zero bits… *except* for
the most significant zero bit. Correct?
If so, then this is an irksome case, since only the most significant bit
from the last nibble can be retained in a 53-bit mantissa.
With the less significant bits all being 0, if the most significant bit
is also 0 then there is no loss of precision from dropping the trailing
bits.
However, if the most significant bit is 1 then losing the zero from the
*second*-most significant bit *is* an actual loss of precision! :-(
So you can specify a 13th hex digit with no loss of precision, but only
if that digit is 0. That’s… not terribly useful. It’s unfortunate that
this fact should make it impossible to specify the LSB in a 4x+1 bits
mantissa as 1.
These are options I can think of:
1. Downgrade this case to a warning. Namely, merely warn about an extra
nibble if mantissa length is not a multiple of 4, but all of the bits
being lost are 0. Possibly even accept dropped 0 bits silently if the
mantissa LSB is 0.
I.e. a 53-bit mantissa 0000000000000 would be silent, 0000000000008
would warn, and 000000000000C would error.
I guess the warning would have to be in a special category of its own
(`hexfpmantlsb`?) so that you could turn it off specifically. But it
would be annoying to be forced to turn off the warning *every time*
you want to specify a float down to the 53rd mantissa bit.
2. Add notation to specify the number of trailing zero bits that should
be considered unspecified instead of explicitly zero.
This would be kinda cryptic and doesn’t seem to have a real upside in
explicitness. Intuitively I thought it should, but it doesn’t because
the float literal doesn’t change length on different systems. A float
literal with 13 hex digits is an error on a system with 52 or fewer
bits of mantissa. And on a system with 56 or more bits of mantissa it
can be represented exactly. So more precision than you intended can
only be inadvertently lost when going from a system with e.g. 55 bits
of mantissa to one with 53 bits: both would require hex floats with
the same number of digits to specify all their mantissa bits but they
differ in how many bits from the last hex digit they can retain. Such
minute differences in precision do not exist in practice.
Any others?
Regards,
--
Aristotle Pagaltzis // <

http://plasmasturm.org/>