# Function returning normalized vector and norm

**URL:** https://discourse.julialang.org/t/function-returning-normalized-vector-and-norm/42285
**Category:** General Usage
**Tags:** linearalgebra
**Created:** [June 30, 2020, 5:22am UTC](https://discourse.julialang.org/t/function-returning-normalized-vector-and-norm/42285 "2020-06-30T05:22:09Z")
**Posts on this page:** 1
**Showing post:** 12

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 30, 2020, 9:15am UTC](https://discourse.julialang.org/t/function-returning-normalized-vector-and-norm/42285/12 "2020-06-30T09:15:50Z")

</div>

I am on the fence about this; it is occasionally useful but also quite easy to implement when needed, so I would tend to agree with @DNF here. Also,

```julia
a = norm(v)
v /= a

```

is not much more complicated — I don’t really mind naming interim values (`v = A*x`), which can actually make the code cleaner.

As pointed out by @mzaffalon, `normalize!` does have a clever trick to fix a numerical issue. But the solution could be just exposing that, eg with

```julia
a = norm(v, p)
v2 = normalize_with(v, a)

```

etc, as it may be useful in other contexts.

---

_[View the full topic](https://discourse.julialang.org/t/function-returning-normalized-vector-and-norm/42285)._
