# Need help fixing an sqrt related error

**URL:** <https://discourse.julialang.org/t/need-help-fixing-an-sqrt-related-error/75084>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 23, 2022, 8:14pm UTC](https://discourse.julialang.org/t/need-help-fixing-an-sqrt-related-error/75084 "2022-01-23T20:14:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [January 23, 2022, 8:14pm UTC](https://discourse.julialang.org/t/need-help-fixing-an-sqrt-related-error/75084/1 "2022-01-23T20:14:13Z")

</div>

Here is the error message:

```julia
ERROR: LoadError: DomainError with -0.038468373019053814:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).

 [12] CO2SYS(PAR1::Vector{Float64}, PAR2::Vector{Float64}, PAR1TYPE::Int64, PAR2TYPE::Int64, SAL::Vector{Float64}, TEMPIN::Vector{Float64}, TEMPOUT::Vector{Float64}, PRESIN::Int64, PRESOUT::Int64, SI::Vector{Float64}, PO4::Vector{Float64}, pHSCALEIN::Int64, K1K2CONSTANTS::Int64, KSO4CONSTANTS::Int64)
    @ CO2System ~/.julia/packages/CO2System/MPyQp/src/CO2System.jl:383

```

Here is the code at line 383 of CO2System.jl  
`sqrSal = sqrt.(SAL)`

What should be the fix? Many thanks!

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [January 23, 2022, 8:17pm UTC](https://discourse.julialang.org/t/need-help-fixing-an-sqrt-related-error/75084/2 "2022-01-23T20:17:06Z")

</div>

You either want `sqrSal = sqrt.(Complex(SAL))` or `sqrSal = sqrt.(max(0, SAL))`. You can’t take the `sqrt` of of a negative real number.

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [January 23, 2022, 8:24pm UTC](https://discourse.julialang.org/t/need-help-fixing-an-sqrt-related-error/75084/3 "2022-01-23T20:24:29Z")

</div>

Many thanks for the solution!
