Skip to content

Conversation

@khwilliamson
Copy link
Contributor

This addresses some of the issues in #18664, beyond the additions of 3e18f72.

  • This set of changes may require a perldelta entry, and I need help deciding.

Comment on lines +480 to +485
but it must be followed by C<p>, an optional sign, and an exponent. The
digits in the exponent are interpreted as being base 10 (digits 0-9 are
accepted), but the actual value is two raised to that power. Thus

5e2 == 5 * 10-squared == 500
0x5p2 == 5 * 2-squared == 20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example with a 2 digit exponent for one of the bitwise bases (hex etc) would better illustrate the base-10-ness of the exponent number vs the base-2-ness of the power.

@sisyphus
Copy link
Contributor

sisyphus commented Dec 8, 2025

This set of changes may require a perldelta entry, and I need help deciding.

I would think that, since no change in behaviour has occurred, perldelta may remain unaltered.

I see this PR introduces the example 05p2 # 20 into the documentation, but there's a nasty little issue when hex/oct/bin integer expressions are allowed to include an exponent.
It's a problem that (I think) affects only those integer values that overflow the IV precision.
Consider the 72-bit value 0x123456789abcdeff00, where the "00" overflows the 64-bit IV.
(Perl-5.42.0, IV size is 64, and NV type is 'double'.)

Owner@DESKTOP-88J497T ~
$ perl -wle 'printf "%.17g\n", 0x123456789abcdeff00p0;'
Integer overflow in hexadecimal number at -e line 1.
Hexadecimal float: mantissa overflow at -e line 1.
1.3117684674637903e+18

Owner@DESKTOP-88J497T ~
$ perl -wle 'printf "%.17g\n", 0x123456789abcdeff00;'
Integer overflow in hexadecimal number at -e line 1.
Hexadecimal number > 0xffffffff non-portable at -e line 1.
3.3581272767073033e+20

(Ignore, for the moment at least, that there are lots of hex numbers "> 0xffffffff" that are quite portable when IVSIZE is 8.)
Both of those one-liners are given valid hex expressions that should be (but are not) treated identically.
The only sign that they are being treated differently is that the second warning differs. And I believe that neither of those "second" warnings have any part in explaining the difference in behaviour.

The latter one-liner produces the correct result, BTW.

I think this would need to be documented or fixed.
Simplest thing might be to have the documentation forbid the inclusion of an exponent in the use of integer expressions.
But I've been doing some investigating on this, and I think it's safe to provide an exponent so long as the given integer value
does not overflow the IV precision.

Are negative exponents in (what are otherwise) hex/oct/bin integer expressions to be allowed ?
I think they DWIM - but, again, only if the given integer expression does not overflow the IV precision.
(One other little caveat with hex/oct/bin floating point values is that mantissa overflow is dealt with by truncation, rather than rounding to nearest - but I don't see that as a blocker.)

@t-a-k might also have some helpful thoughts on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants