# Possible bug in determinant calculation

**URL:** <https://discourse.julialang.org/t/possible-bug-in-determinant-calculation/20323>\
**Category:** Numerics\
**Created:** [January 31, 2019, 4:19pm UTC](https://discourse.julialang.org/t/possible-bug-in-determinant-calculation/20323 "2019-01-31T16:19:23Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![ledwards](https://avatars.discourse-cdn.com/v4/letter/l/da6949/32.png) [@ledwards](https://discourse.julialang.org/u/ledwards)\
**Post date:** [November 15, 2021, 8:45pm UTC](https://discourse.julialang.org/t/possible-bug-in-determinant-calculation/20323/21 "2021-11-15T20:45:28Z")

</div>

I know that this has been fixed, but I wanted to mention that the Bareiss algorithm produces exact results with integer matrices, and is simpler than LU with pivoting. I wrote a templated C++ Bareiss implementation that gives the correct result with integer, float, and GMP mpf\_t matrices.

I’ll also second the suggestion to have the det() function return the same type as the argument.

Determinants do have pedagogical uses… e.g. they are used heavily in G. Baley Price’s Multivariable Analysis extending differentiation to higher dimensions. The mechanics, if you will, are ugly, but conceptually Price’s approach is intuitive (to my mind).

Larry

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 15, 2021, 8:58pm UTC](https://discourse.julialang.org/t/possible-bug-in-determinant-calculation/20323/22 "2021-11-15T20:58:46Z")

</div>

> [@ledwards](#):
>
> I know that this has been fixed, but I wanted to mention that the Bareiss algorithm produces exact results with integer matrices, and is simpler than LU with pivoting. I wrote a templated C++ Bareiss implementation that gives the correct result with integer, float, and GMP mpf\_t matrices.

Julia 1.7 uses the Bareiss algorithm for determinants of `BigInt` matrices. (The implementation is also provided in a generic form in [`LinearAlgebra.det_bareiss`](https://github.com/JuliaLang/julia/blob/4b99bc8443344f2ca54fc32d726bf65dc2425df1/stdlib/LinearAlgebra/src/generic.jl#L1632-L1674) if you want to use it for some other type.)

[Previous page](https://discourse.julialang.org/t/possible-bug-in-determinant-calculation/20323.md?page=1)
