# Work around for \`eigvals!(Matrix{Dec64})\`?

**URL:** <https://discourse.julialang.org/t/work-around-for-eigvals-matrix-dec64/98680>\
**Category:** General Usage\
**Created:** [May 11, 2023, 1:44pm UTC](https://discourse.julialang.org/t/work-around-for-eigvals-matrix-dec64/98680 "2023-05-11T13:44:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AwesomeQuest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/awesomequest/32/38910_2.png) [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Post date:** [May 11, 2023, 1:44pm UTC](https://discourse.julialang.org/t/work-around-for-eigvals-matrix-dec64/98680/1 "2023-05-11T13:44:33Z")

</div>

Reading the code for `eigvals!`, it always tries to promote the matrix to some kind of “normal” float so it can work with `LAPACK.geevx!`… I think. But that clearly defeats the purpose of using something like DecFP.

```julia
julia> using DecFP, LinearAlgebra

julia> p = [d"4" d"7"; d"1" d"30"]
2×2 Matrix{Dec64}:
 4.0 7.0
 1.0 30.0

julia> eigvals!(p)
ERROR: MethodError: no method matching eigvals!(::Matrix{Dec64})

```

Why doesn’t Julia have a default function for `eigvals` that doesn’t rely on external libraries? Is there a package that solves this?

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [May 11, 2023, 1:56pm UTC](https://discourse.julialang.org/t/work-around-for-eigvals-matrix-dec64/98680/2 "2023-05-11T13:56:57Z")

</div>

Could you check if [GitHub - JuliaLinearAlgebra/GenericLinearAlgebra.jl: Generic numerical linear algebra in Julia](https://github.com/JuliaLinearAlgebra/GenericLinearAlgebra.jl) helps with this?

---

<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:** [May 11, 2023, 2:30pm UTC](https://discourse.julialang.org/t/work-around-for-eigvals-matrix-dec64/98680/3 "2023-05-11T14:30:54Z")

</div>

> [@AwesomeQuest](#):
>
> Reading the code for `eigvals!`, it always tries to promote the matrix to some kind of “normal” float so it can work with `LAPACK.geevx!`… I think. But that clearly defeats the purpose of using something like DecFP.

Computing eigenvalues _inherently_ defeats the purpose of using a type like `Dec64`. Even if the input matrix consists of exact `Dec64` decimals, the eigenvalues/vectors will generally _not_ be decimal and will have roundoff errors. So you might as well convert the matrix to `Float64` when calling `eigvals`.

> [@AwesomeQuest](#):
>
> Why doesn’t Julia have a default function for `eigvals` that doesn’t rely on external libraries? Is there a package that solves this?

Because eigenvalue computation is extremely nontrivial, so it’s not a matter of just writing a 60-line textbook-style fallback function like [we can for LU](https://github.com/JuliaLang/julia/blob/6618d4416d23c71c676cd697a99df6ef63d0e2ae/stdlib/LinearAlgebra/src/lu.jl#L132-L193) factorization. That’s why eigenvalue computation for generic number types was left to packages like [GenericLinearAlgebra.jl](https://github.com/JuliaLinearAlgebra/GenericLinearAlgebra.jl) and [GenericSchur.jl](https://github.com/RalphAS/GenericSchur.jl).

But in the case of `Dec64`, as I said above, you might as well convert to `Float64` and use the high-performance LAPACK implementation. (There is more benefit to generic linear algebra if you have an extended-precision type like `Dec128`, but even then it is probably faster to go with a binary FP type like [DoubleFloats](https://github.com/JuliaMath/DoubleFloats.jl) than to use slow software-based decimal FP.)

Really, the only reason to use decimal FP is in situations where you need to exactly preserve human inputs and exact calculations thereon, e.g. for financial records. (Or for pedagogy.)
