Question about singular matrix inversion

Correct. You can watch what happens in more detail by breaking down the inversion into it’s constituent steps. Start by computing the LU factorization of the matrix:

ulia> A = [0.23 0.23; 0.3 0.3]
2×2 Matrix{Float64}:
 0.23  0.23
 0.3   0.3

julia> (; P, L, U) = lu(A)
LU{Float64, Matrix{Float64}, Vector{Int64}}
L factor:
2×2 Matrix{Float64}:
 1.0       0.0
 0.766667  1.0
U factor:
2×2 Matrix{Float64}:
 0.3  0.3
 0.0  2.96059e-18

Look at the last diagonal element in U: it should be zero, but we got 2.96e-18. Compared to the other numbers here, 2.96e-18 is really close to zero; in fact, it’s closer to zero than the actual number hiding behind 0.3 is to the real number 0.3. (Try big"0.3" - 0.3 to see this.) But since it’s not exactly zero, the remaining steps of the inversion will succeed and give a bogus answer:

julia> Ainv = U \ (L \ P)
2×2 Matrix{Float64}:
 -3.3777e17   2.58957e17
  3.3777e17  -2.58957e17

The reason your second example fails as expected is not due to the number type; in fact, the type must be converted to float before the factorization can proceed anyway. The difference is simply that for these particular numbers, the algorithm used for LU factorization happens to return an exact instead of approximate zero pivot:

julia> (; P, L, U) = lu([1.0 1.0; 2.0 2.0]; check=false)
Failed factorization of type LU{Float64, Matrix{Float64}, Vector{Int64}}

julia> U
2×2 Matrix{Float64}:
 2.0  2.0
 0.0  0.0
4 Likes