MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #15234] Hexadecimal literals are not parsed correctly #4822

Closed MichaelChirico closed 4 years ago

MichaelChirico commented 4 years ago

GNU R does not parse floating point hexadecimal literals correctly.

In notation without exponent part GNU R discards decimal points when parsing hexadecimal literals:

0x111 # Result: 273 # Status: OK

0x11.1 # Result: 273 # Status: should be 17.0625

0x1.1.1 # Result: 273 # Status: should raise an error

0x....1....1....1 # Result: 273 # Status: should raise an error

In notation with exponent ([pP] option) last decimal point is taken into consideration and all earlier decimal points are ignored:

0x11.1p0 # Result: 17.0625 # Status: OK

0x1.1.1p0 # Result: 17.0625 # Status: should raise an error

0x....1....1....1p0 # Result: 17.0625 # Status: should raise an error

Additionally hexadecimal literals are documented very briefly in "R Language Definition" document.

Bug manifests itself on Windows:

sessionInfo()

R version 2.15.0 (2012-03-30) Platform: x86_64-pc-mingw32/x64 (64-bit)

locale: [1] LC_COLLATE=Polish_Poland.1250 LC_CTYPE=Polish_Poland.1250
[3] LC_MONETARY=Polish_Poland.1250 LC_NUMERIC=C
[5] LC_TIME=Polish_Poland.1250

attached base packages: [1] stats graphics grDevices utils datasets methods base

and under Linux:

sessionInfo() 

R version 2.15.1 (2012-06-22) Platform: x86_64-pc-linux-gnu (64-bit)

locale: [1] C

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] seqinr_3.0-6 ade4_1.5-0


METADATA

MichaelChirico commented 4 years ago

Our documentation doesn't say we support hex literals for floating point values, so all of these could be treated as syntax errors. However, we do support C99 notation "0x11.1p0" as you saw, so really the bugs here are that we aren't catching malformed literals like 0x11.1, or 0x1.1.1, etc., and that we don't document that we expect C99 conventions.


METADATA

MichaelChirico commented 4 years ago

Fixed in R-devel as of r62736. I don't plan to backport to R-patched, since well-formed constants were being recognized properly, this only makes the parsing more strict.


METADATA