-
Notifications
You must be signed in to change notification settings - Fork 566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does Perl formally support exponential notation for octal numbers? #18664
Comments
Based on some quick, non-extensive testing, it seems that both the octal and hex forms of floating point (bareword) values are no longer a fatal error as of perl-5.22.0. I'd be hopeful that this could be attended to by amending the documentation as needed. |
If this is officially supported (#18664), here's a patch for the docs.
On Cygwin built with quadmath, binary and octal floating point literals were silently treated as hexadecimals before 5.28.0. From 5.28.0 and onwards, both binary, octal, and hexadecimals seem to work correctly. (And from 5.33.5 and onwards, the "0o" prefix is supported.) |
Not surprisingly, perl also accepts binary floating point literals.
In addition, currently perl does not seem to provide a standard way to convert floats to octal/binary form. IMHO it might be better to note in the document that the conversions are one-way. |
Going the other way is not straight forward because of limitations in the way perl handles floating point literals. For example, here is the number with the smallest magnitude using binary64 (a.k.a. double) floating point numbers:
The following represents the same number. A warning is given, but the result is correct.
The following also represents the same number. Again a warning is given, but the result is incorrect.
By the way, all three representations work fine if perl is compiled with quadmath support, but of course in that case the numbers are no longer the smallest possible magnitude. |
It's not clear to me whether support for octal/binary floating point literals were intended when the code was originally written, or it just naturally came about from the way the implementation is integrated into the implementation of parsing hex/octal/binary integers. We have fixed some bugs specific to octal/binary floating point literals, so considering them supported and documenting them is reasonable. |
For me. on Windows (building perl with mingw-w64 ports of gcc-8.3.0) the "0o" formatting (but not the "0x" or "0") is invalid prior to perl-5.33.5:
Is it the same on other systems ? Also, when the 'p+exponent' part is left out, the decimal point is taken to be the dot operator, which seems a little odd:
A similar thing happens wrt to "0x":
And then for me (perl-5.33.5 and later only):
It's a pity about that. Can it be covered via documentation ? ... or do we need to look at altering the behaviour ? |
It is the same on Cygwin (as I mentioned above). It should be the same on all systems, since the support for the "0o" prefix was introduced with the commit b728918 between v5.33.4 and v5.33.5.
At least this is as documented. The literal is only treated as a floating point number if the exponent is present. As a consequence, if the exponent is not present, the bin/oct/hex number is treated as an integer. |
On Mon, Mar 29, 2021 at 6:59 PM Peter John Acklam ***@***.***>
wrote
At least this is as documented. The literal is only treated as a floating
point number if the exponent is present. As a consequence, if the exponent
is not present, the bin/oct/hex number is treated as an integer.
Good to know that the behaviour is already documented. (Thanks.)
IIUC, when the exponent is absent, the number before the dot is treated as
a bin/oct/hex integer, and the number following the dot is treated as a
decimal integer (and concatenated onto the end of the first integer).
It's hard to see how this could ever be considered as DWIMing.
If I wanted that to happen, I would write the expression as:
0x1 . 55
not:
0x1.55.
As regards decimal barewords, perl DWIMs for (eg) both:
2.18446744073709551615
and
2 . 18446744073709551615
(see below) so I don't know why it can't DWIM for the bin/oct/hex variant.
Actually, I'm sure it *could* DWIM if someone wanted to make the effort to
have it do so.
C:\>perl -MDevel::Peek -wle "Dump(2.18446744073709551615);"
SV = NV(0x3488c0) at 0x3488d8
REFCNT = 1
FLAGS = (NOK,READONLY,PROTECT,pNOK)
NV = 2.1844674407371
C:\>perl -MDevel::Peek -wle "Dump(2 . 18446744073709551615);"
SV = PV(0x58cf88) at 0x47df70
REFCNT = 1
FLAGS = (PADTMP,POK,READONLY,PROTECT,pPOK)
PV = 0x4ed298 "218446744073709551615"\0
CUR = 21
LEN = 32
Obviously, this perl's nvtype is double and ivsize is 8.
Anyway ... I'll settle for the fact that at least some productive gains
have been achieved here, and not worry too much about what else might be
achievable.
Cheers,
Rob
|
Closing this as inactive so it's not in my list of open issues. |
If this is documented, I'm not seeing it... |
Neither do I. The examples in perldata.pod (see below) ought to mention octal and binary floating point literals. Just one example of each below the hexadecimal floating point example would be useful.
A few paragraphs further down I find the following, which ought to mention octal and binary floating point literals in addition to hexadecimal:
|
What is going on? If Perl supports octal and binary floating point literals – and this is not documented – I cannot see how this issue can be seen as completed. |
It's not completed, and it can't be completed. It's just closed. Either someone has to decide that Perl supports this and we document it, or no one makes the decision and we don't document it and accept it as a curious side effect that perl may later not support. It's been four years without no decision. No decision is the decision that perl doesn't guarantee support for this and it's a curiousity. It's not completed; it's closed. Later, if someone makes the decision to support it, they can document it. It's basic issue management to not let tickets live forever, especially if there will be no action on them. Unactionable long-lived tickets pollute the backlog such that people don't mind more unactionable long-lived tickets, and eventually this makes the accumulating backlog so noisy that even good tickets drown in it. And, not only does this pollute the perl queue, but also the list of issues I have under my own username. As such, I don't want this unactionable issue in my personal backlog. It's a problem for me working toward zero inbox. |
I see your point. I don't know who has the authority to say that binary and octal floating point literals are officially supported, but I'd like to point out that both binary and octal floating point literals are tested in |
Constant overloads for them were fixed in 5.32 (#14791) so I believe that is sufficient indication that they are intentionally supported. |
Then don't mark it as "completed". |
This (possibly accidental) feature has had tests since commit 58be576 and bug fixes such as commit 2cb5a7e. See also the discussion in GH issues Perl#16114 and Perl#14791, particularly jhi's comment in <Perl#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 Perl#18664.
Description
perldata does not mention a octal floating point form, but apparently it works:
Is this intended? If so, it should be added to the list of scalar value constructors.
If this is not intended, I guess it should stop doing that.
Perl configuration
The text was updated successfully, but these errors were encountered: