JuliaPhysics / JuliaPhysics/Unitful.jl
Addition of temperatures revisited
- Dominant language
- Julia
- Stars
- 675
- Forks
- 124
- Avg merge
- 3h 38m
- Merged PRs (30d)
- 1
Description
Hello,
not sure if it's by design, but basic mathematical operators with NaNs throws an error (it does work with minus though! But returns the wrong unit).
edit - It seems that the problem only occurs with Celsius, as far as I can tell and to e related to Affine units.
```julia
julia> NaN*°C + NaN*°C
ERROR: AffineError: an invalid operation was attempted with affine quantities: NaN °C + NaN °C
Stacktrace:
[1] +(::Unitful.Quantity{Float64,�,Unitful.FreeUnits{(K,),�,Unitful.Affine{-5463//20}}}, ::Unitful.
Quantity{Float64,�,Unitful.FreeUnits{(K,),�,Unitful.Affine{-5463//20}}}) at C:\Users\Marie\.julia\pa
ckages\Unitful\b6IPw\src\quantities.jl:108
[2] top-level scope at none:0
julia> NaN + NaN
NaN
julia> NaN*°C - NaN*°C # returns a Kelvin
NaN K
```
I think it would be best to just return NaNs. I have some big 3D Array and there's always some NaNs in it and it sadly throws an error.
Thanks for your effort!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with src/quantities.jl around line 108, where the stack trace reports the affine quantity operation. Reproduce the Celsius NaN addition and subtraction examples from the issue, then verify that the completed behavior handles NaN affine quantities without the reported error and preserves the expected unit behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100