dgkf / R

An experimental reimagining of R
https://dgkf.github.io/R
GNU General Public License v3.0
135 stars 6 forks source link

Create integers by default if all values are integer-valued #77

Open sebffischer opened 9 months ago

sebffischer commented 9 months ago

I am wondering what the reason is why R creates doubles by default even if all values are integer-valued.

typeof(1)
#> [1] "double"

Created on 2023-12-27 with reprex v2.0.2

One reason I can think of is that doubles are 64 bit, while integers are 32 bit by default, so creating doubles allows for a greater range of values.

dgkf commented 8 months ago

Yeah - I'm not exactly sure either. Perhaps because in statistics, it's rare that you work with integers aside from the factor enum representation. Assuming that most use cases would eventually do some calculations with the value, perhaps it's better just to start with a double.

In my experience, I usually use integer values for general programming as individual values as index offsets or other constant values. When I use floating point math, it's usually large matrices to store data or fit models, so the most performance-intensive conversions would probably happen in those scenarios. Perhaps that was part of the rationale.