As a general rule, you should never expect exact answers from floating point calculations. You are correct that in principle, the determinant of an integer matrix, which involves only addition, subtraction and multiplication, should give an integer result. And this would (probably) be the case if R used the naive algorithm to compute the determinant.
However, the naive algorithm involves a summation over all N! permutations, which is enormously inefficient, so instead R uses some other method. I don't know what this method is -- you can look at the C source if you want, but my guess is that they do a matrix decomposition X=LU
and then return det(X)=det(L)det(U)
, where the determinant of L
and U
involves simply multiplying the diagonals.
Some more info can be found by looking at the function det
, shown below. As you can see, what it actually does is computes the log of the determinant, and then exponentiates it, so there is no reason to believe the result is going to be an integer.
> det
function (x, ...)
{
z <- determinant(x, logarithm = TRUE, ...)
c(z$sign * exp(z$modulus))
}