# Arithmetic on colors

**URL:** <https://discourse.julialang.org/t/arithmetic-on-colors/85297>\
**Category:** General Usage\
**Tags:** colors\
**Created:** [August 4, 2022, 11:43am UTC](https://discourse.julialang.org/t/arithmetic-on-colors/85297 "2022-08-04T11:43:26Z")\
**Posts on this page:** 1\
**Showing post:** 12

<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:** [August 4, 2022, 12:48pm UTC](https://discourse.julialang.org/t/arithmetic-on-colors/85297/12 "2022-08-04T12:48:09Z")

</div>

> [@DNF](#):
>
> But I get:
> 
> ```julia
> julia> ColorVectorSpace.norm(cols[2] .- cols[1])^2 * 3
> 0.0
> 
> ```

Looks like this is underflow due to the fixed-point precision:

```julia
julia> cols[2] - cols[1]
RGB{N0f8}(0.008,0.008,0.008)

julia> norm(cols[2] - cols[1])
0.0

julia> norm(RGB{Float64}(cols[2] - cols[1]))
0.00784313725490196

```

In particular, the problem stems from the underflow:

```julia
julia> N0f8(0.008)^2
0.0N0f8

```

Arguably, this should be changed — since the output of `norm` is a `Float64`, this computation should be performed by promoting operands to the output precision. Or at the very least some scaling should be done to prevent spurious overflow/underflow (similar to what `norm` and `hypot` do for floating-point vectors).

(_Update_: Filed issue [ColorVectorSpace.jl#183](https://github.com/JuliaGraphics/ColorVectorSpace.jl/issues/183).)

---

_[View the full topic](https://discourse.julialang.org/t/arithmetic-on-colors/85297)._
