JuliaLang/julia

Pick a hex literal standard and use it consistently

Open

#11,212 opened on May 9, 2015

View on GitHub
 (21 comments) (0 reactions) (1 assignee)Julia (48,709 stars) (5,773 forks)batch import
designhelp wantedparser

Description

The hexadecimal integer notation normally allows for both 0x and 0X (C, Python, IEEE 754-2008). Julia only supports the lower case variant.

Octal and binary constants have similar issues, except Julia is probably alone with 0o777 for octal notation, and uppercase could be hard to read - still it is inconsistent with common use of case insensitivity in numeric constants.

Hexadecimal floating point (HFP) constants are affected by the same issue. Julia follows the C99 specification with the exception of 0X upper case prefix.

However, the HFP standard is a bit inconsistent in not allowing for the power suffix to be omitted if there is a (hexa)decimal point. Python makes this optional. It is not very elegant to type 0x1p0 instead of 0x1.0

The question is whether to adhere strictly to standard, or follow Pythons more intuitive approach. Pythons documented syntax is not exact; the runtime also allows for upper case everywhere in HFP, and an absent integer part, like Julia and C99.

Additionally, a binary floating point notation has already been requested in #9371. This would add to consistency, but is not supported by C99. The main motivation of HFP notation is probably to avoid loss of precision between machine and printet representation - which binary notation would not improve upon. Binary would, however, make certain binary polynomials more pleasant to deal with - most likely for assigning to other datatypes with larger precision than float.

Python [sign] ['0x'] integer ['.' fraction] ['p' exponent] https://docs.python.org/2/library/stdtypes.html

C99, section 6.4.4.2 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

http://www.exploringbinary.com/hexadecimal-floating-point-constants/

Contributor guide