Return the Number of Bits in a S-PLUS Integer

DESCRIPTION:

Return the number of bits in a S-PLUS integer, providing a convenient way to distinguish between 32-bit and 64-bit versions of S-PLUS.

USAGE:

bits.per.integer()

VALUE:

an integer value giving the number of bits used to store a S-PLUS integer in the currently running version of S-PLUS.

DETAILS:

This function simply takes the size of an integer vector of length 1 (in bytes), subtracts the size of an integer vector of length zero (in bytes), then multiplies by 8 to obtain the bit size. This function is primarily useful in testing whether you are currently running a 32-bit or 64-bit version of S-PLUS.

The larger the bits per integer, the larger the integer value you can calculate. For example, in the 32-bit version of S-PLUS for Solaris, the largest integer (as defined by .Machine$integer.max) is 2147483647. In the 64-bit version, the largest integer is 9223372036854775807, which is 2^32 times larger.

If you are writing C and Fortran code for use with S-PLUS, you must ensure that you are passing values of the correct type. S-PLUS integers correspond to C longs and Fortran integers, respectively. If you pass values of the correct type, the makefile created by Splus CHAPTER automatically uses the appropriate flags to compile for the version of S-PLUS you are planning to use. If you create code in a single chapter that you want to use on both 32- and 64-bit versions, you will need to create two makefiles, one for each version. In this case, it is best to give the compiled shared libraries separate names, such as S32.so and S64.so. If you do this, you will need to open these files directly using the dyn.open function.

SEE ALSO:

, , .

EXAMPLES:

.First <- function(){
                if(bits.per.integer()==64){
                        cat("64-bit S-PLUS\n")
                   }            
                if(bits.per.integer()==32){
                        cat("32-bit S-PLUS\n")          
                }
}