Given two integers:
a <- 1L
b <- 1L
As I would expect, adding, subtracting, or multiplying them also gives an integer:
class(a + b)
# [1] "integer"
class(a - b)
# [1] "integer"
class(a * b)
# [1] "integer"
But dividing them gives a numeric:
class(a / b)
# [1] "numeric"
I think I can understand why: because other combinations of integers (e.g. a <- 2L
and b <- 3L
) would return a numeric, it is the more general thing to do to always return a numeric.
Now onto exponentiation:
class(a ^ b)
# [1] "numeric"
This one is a bit of a surprise to me. Can anyone explain why it was designed this way?