From maechler at stat.math.ethz.ch  Mon Apr 18 12:06:48 2005
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Mon Apr 18 12:06:57 2005
Subject: [Rd] RFC: hexadecimal constants and decimal points
In-Reply-To: <40932.130.225.48.22.1113809622.squirrel@www.stats.uwo.ca>
References: <Pine.LNX.4.61.0504171136210.13254@gannet.stats>
	<20050417135001.GA14537@jtkpc.cmp.uea.ac.uk>
	<Pine.LNX.4.61.0504171445040.15170@gannet.stats>
	<40932.130.225.48.22.1113809622.squirrel@www.stats.uwo.ca>
Message-ID: <16995.34488.148220.500383@stat.math.ethz.ch>

>>>>> "Duncan" == Duncan Murdoch <murdoch@stats.uwo.ca>
>>>>>     on Mon, 18 Apr 2005 03:33:42 -0400 (EDT) writes:

    >> On Sun, 17 Apr 2005, Jan T. Kim wrote:
    >> 
    >>> On Sun, Apr 17, 2005 at 12:38:10PM +0100, Prof Brian Ripley wrote:
    >>>> These are some points stimulated by reading about C history (and
    >>>> related in their implementation).
    >>>> 
    >>>> 
    >>>> 1) On some platforms
    >>>> 
    >>>>> as.integer("0xA")
    >>>> [1] 10
    >>>> 
    >>>> but not all (not on Solaris nor Windows).  We do not define what is
    >>>> allowed, and rely on the OS's implementation of strtod (yes, not
    >>>> strtol).
    >>>> It seems that glibc does allow hex: C99 mandates it but C89 seems not
    >>>> to
    >>>> allow it.
    >>>> 
    >>>> I think that was a mistake, and strtol should have been used.  Then C89
    >>>> does mandate the handling of hex constants and also octal ones.  So
    >>>> changing to strtol would change the meaning of as.integer("011").
    >>> 
    >>> I think interpretation of a leading "0" as a prefix indicating an octal
    >>> representation should indeed be avoided. People not familiar to C will
    >>> have a hard time understanding and getting used to this concept, and
    >>> in addition, it happens way too often that numeric data are provided
    >>> left-
    >>> padded with zeros.

    Duncan> I agree with this:  011 should be 11, it should not be 9.

I agree (with Duncan and Jan).

I'm sure the current (decimal) behavior is implicitly used in
many places of people's code that reads text files and
manipulates it.

Martin


[Rd] RFC: hexadecimal constants and decimal points
Martin Maechler