Skip to content

Commit 3e18f72

Browse files
committed
perldata: document binary/octal floating-point constants
This (possibly accidental) feature has had tests since commit 58be576 and bug fixes such as commit 2cb5a7e. See also the discussion in GH issues #16114 and #14791, particularly jhi's comment in <#16114 (comment)>: > Relatedly: I remember there being a known "loophole" so that the > scanning code currently accidentally, falling naturally out of the > implementation, is also doing "binary fp" and "octal fp". Ah yes: > > ./miniperl -wle 'print 0b11.1p0' > 3.5 > ./miniperl -wle 'print 011.1p0' > 9.125 > > This is probably not documented anywhere. I can't now think of the > right search terms to find any previous discussion, there was something > about should this be rejected, or not. If not (as is currently the > case), maybe this possibly should be tested, documented, and made > official? With the documentation in this patch and the existing tests, I guess the feature is now official. Fixes #18664.
1 parent fe38c5a commit 3e18f72

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pod/perldata.pod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ integer formats:
444444
0o12_345 # alternative octal (introduced in Perl 5.33.5)
445445
0b011011 # binary
446446
0x1.999ap-4 # hexadecimal floating point (the 'p' is required)
447+
07.65p2 # octal floating point (the 'p' is required)
448+
0o7.65p2 # alternative octal floating point
449+
0b101.01p-1 # binary floating point (the 'p' is required)
447450

448451
You are allowed to use underscores (underbars) in numeric literals
449452
between digits for legibility (but not multiple underscores in a row:
@@ -478,6 +481,9 @@ potential source of (low-order) differences are the floating point
478481
rounding modes, which can differ between CPUs, operating systems,
479482
and compilers, and which Perl doesn't control.
480483

484+
Octal and binary floating point numbers use the same format as hexadecimal
485+
floating point numbers, but limited to binary and octal digits, respectively.
486+
481487
You can also embed newlines directly in your strings, i.e., they can end
482488
on a different line than they begin. This is nice, but if you forget
483489
your trailing quote, the error will not be reported until Perl finds

0 commit comments

Comments
 (0)