Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use 32-bit float instead of 64-bit in R dataframes?

Tags:

r

The issue I'm having is related to memory. I'm doing financial calculations on dollar amounts and currently my float precision is 64-bits. I'd like to reduce the precision down to at least 32-bits but so far have not found a way to specify this in R. Ideally, this would just be applied to a dataframe that has a number of columns some are ints and some are floats.

like image 798
Dan Crawford Avatar asked May 23 '15 15:05

Dan Crawford


People also ask

Is float guaranteed to be 32-bit?

Knowing that the sizeof(float) is 32 bits may be sufficient, in general, but insufficient in all cases. IEEE 758 defines the well known 32-bit binary32 which is commonly implemented. But IEEE 758 also defines a 32-bit decimal32, which is primarily use for storage and not computation.

Are floats 32 or 64-bit?

Floats generally come in two flavours: “single” and “double” precision. Single precision floats are 32-bits in length while “doubles” are 64-bits. Due to the finite size of floats, they cannot represent all of the real numbers - there are limitations on both their precision and range.

What is the range of float with 64 bits?

A double precision, floating-point number is a 64-bit approximation of a real number. The number can be zero or can range from -1.797693134862315E+308 to -2.225073858507201E-308, or from 2.225073858507201E-308 to 1.797693134862315E+308.


1 Answers

No, there is not -- at least not in 'base R' which has only one integer and numeric (floating point) type each, and their sizes are fixed.

You can inspect them (and more) via .Machine -- see help(".Machine").

Now, for your dollar amounts you could of course resort to expressing things in cents instead in which case you could integer -- which is generally half the size of numeric.

like image 103
Dirk Eddelbuettel Avatar answered Sep 22 '22 18:09

Dirk Eddelbuettel