Skip to content

Difference between 10 and 10L

4 messages · brwin338, William Dunlap, Brian Ripley +1 more

#
[1] "numeric"
  > class(10L)
  [1] "integer"
  > class(10i)
  [1] "complex"

Why not 10I for integer?  Perhaps because "I" and "l"
look too similar, perhaps because "i" and "I" sound
too similar.  The "L" does not mean "long": integers
are 4 bytes long.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
#
On 04/05/2012 00:43, William Dunlap wrote:
Actually it does: this notation dates from the C language on 16-bit 
computers where integers were 16-bits and longs were 32-bit (and R has 
no 'long' type).

The author of this in R never explained why he chose the notation, but 
it is shorter than as.integer(10), and more efficient as the coercion is 
done at parse time.

(C has a different convention: 10 is integer, 10. is double.  Changing 
to that would have altered existing code, since e.g. 4294967296 is not a 
valid integer.)

  
    
#
On Thu, May 03, 2012 at 07:32:46PM -0400, brwin338 wrote:
Hi.

The help page ?"1L" or, equivalently, ?NumericConstants says

     An numeric constant immediately followed by ?L? is regarded as an
     ?integer? number when possible (and with a warning if it contains
     a ?"."?).

Try typeof(1) and typeof(1L).

Petr Savicky.