Quantcast
Channel: Bogumił Kamiński – R-bloggers
Viewing all articles
Browse latest Browse all 49

Hexadecimal literals in GNU R

$
0
0

(This article was first published on R snippets, and kindly contributed to R-bloggers)
Recently I have used hexadecimal numbers in GNU R. The way they are parsed surprised me and is inconsistent with Java. As R Language Definition pdf only briefly mentions hexadecimal numbers here is what I have found.

First I have checked the following code:

0x11
# 17
0x1.1
# 17

I seemed that GNU R drops the decimal point. So I have checked notation with exponent being power of 2 (as in Java):

0x1.1p0
# 1.0625
0x1.1p4
# 17

Now decimal point is correctly taken into account so I have checked further.

In the notation without exponent part GNU R just discards decimal points as in this example:

0x111
# 273
0x1.1.1
# 273
0x....1....1....1
# 273

However, in notation with exponent last decimal point is taken into consideration and all earlier decimal points are ignored:

0x11.1p0
# 17.0625
0x1.1.1p0
# 17.0625
0x....1....1....1p0
# 17.0625

In summary - handling of hexadecimal literals in GNU R is nonstandard and at least for me - unexpected.

To leave a comment for the author, please follow the link and comment on his blog: R snippets.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series,ecdf, trading) and more...

Viewing all articles
Browse latest Browse all 49

Trending Articles