title: What causes `AssertionError` when asserting a diagonalized vector in Julia?
body: <p>I've been doing some <a href="https://github.com/JuliaAcademy/JuliaTutorials/tree/main/introductory-tutorials/intro-to-julia" rel="nofollow noreferrer">exercises in julia</a>, and I am currently trying to <code>@assert</code> a vector that has been diagonalized into a matrix against a &quot;solution matrix&quot; given in the exercise notebook. However, I get an <code>AssertionError</code> when asserting my code against the provided solution. Example of my code:</p>
  <pre><code>julia&gt; using LinearAlgebra
  
  julia&gt; A =
  [
   140   97   74  168  131
    97  106   89  131   36
    74   89  152  144   71
   168  131  144   54  142
   131   36   71  142   36
  ]
  
  5×5 Matrix{Int64}:
   140   97   74  168  131
    97  106   89  131   36
    74   89  152  144   71
   168  131  144   54  142
   131   36   71  142   36
  
  julia&gt; A_eigv = eigen(A).values
  
  5-element Vector{Float64}:
   -128.49322764802145
    -55.887784553057
     42.752167279318854
     87.16111477514494
    542.4677301466137
  
  julia&gt; A_diag = Diagonal(A_eigv)
  
  5×5 Diagonal{Float64, Vector{Float64}}:
   -128.493     ⋅        ⋅        ⋅         ⋅ 
       ⋅     -55.8878    ⋅        ⋅         ⋅ 
       ⋅        ⋅      42.7522    ⋅         ⋅ 
       ⋅        ⋅        ⋅      87.1611     ⋅ 
       ⋅        ⋅        ⋅        ⋅      542.468
  
  julia&gt; @assert A_diag ==  [-128.493    0.0      0.0      0.0       0.0;
      0.0    -55.8878   0.0      0.0       0.0;
      0.0      0.0     42.7522   0.0       0.0;
      0.0      0.0      0.0     87.1611    0.0;
      0.0 0.0      0.0      0.0     542.468]
  
  AssertionError: A_diag == [-128.493 0.0 0.0 0.0 0.0; 0.0 -55.8878 0.0 0.0 0.0; 0.0 0.0 42.7522 0.0 0.0; 0.0 0.0 0.0 87.1611 0.0; 0.0 0.0 0.0 0.0 542.468]
  
  Stacktrace:
   [1] top-level scope
     @ In[90]:1
   [2] eval
     @ ./boot.jl:360 [inlined]
   [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
     @ Base ./loading.jl:1094
  </code></pre>
  <p>My inital assumption was that a difference in number of decimals was the cause of the error. I therefore replaced <code>==</code> with <code>≈</code> (<code>\approx</code>). However, as the code example below shows, the error persists:</p>
  <pre><code>julia&gt; @assert A_diag ≈ #\approx
  [-128.493    0.0      0.0      0.0       0.0;
      0.0    -55.8878   0.0      0.0       0.0;
      0.0      0.0     42.7522   0.0       0.0;
      0.0      0.0      0.0     87.1611    0.0;
      0.0 0.0      0.0      0.0     542.468]
  
  AssertionError: A_diag ≈ [-128.493 0.0 0.0 0.0 0.0; 0.0 -55.8878 0.0 0.0 0.0; 0.0 0.0 42.7522 0.0 0.0; 0.0 0.0 0.0 87.1611 0.0; 0.0 0.0 0.0 0.0 542.468]
  
  Stacktrace:
   [1] top-level scope
     @ In[97]:1
   [2] eval
     @ ./boot.jl:360 [inlined]
   [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
     @ Base ./loading.jl:1094
  
  </code></pre>
  <p>I've been reading through my code multiple times now, and I am at a loss. The values in my diagonal matrix (<code>A_diag</code>) are seemingly identical to the solution matrix. Furthermore, setting the statement to approximately equal (<code>\approx</code>) renders the same error, so I assume I can count out decimal error.</p>
  <p>My main question is: <strong>What causes the <code>AssertionError</code>?</strong></p>