# Performance of norm function

**URL:** <https://discourse.julialang.org/t/performance-of-norm-function/14709>\
**Category:** Performance\
**Tags:** linearalgebra\
**Created:** [September 8, 2018, 7:03pm UTC](https://discourse.julialang.org/t/performance-of-norm-function/14709 "2018-09-08T19:03:34Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [March 28, 2021, 1:13pm UTC](https://discourse.julialang.org/t/performance-of-norm-function/14709/21 "2021-03-28T13:13:04Z")

</div>

To calculate that correctly, initialize x and y as BigFloats using strings.

```julia
julia> x = BigFloat("3e-200"); y = BigFloat("4e-200");
julia> sqrt(x^2 + y^2) 
4.99999999999999999999999999999999999999999999999999999999999999999999999997e-200

```

otherwise the erosion has already occured when the conversion to BigFloat happens

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [March 28, 2021, 1:15pm UTC](https://discourse.julialang.org/t/performance-of-norm-function/14709/22 "2021-03-28T13:15:49Z")

</div>

Yes, I was responding to “All it would require is doing the accumulation (not the squaring) in twice precision.” If efficiency is the concern, better to use the n-d generalization of the hypot algorithm |x| \sqrt{1 +(y/x)^2} in the original precision, where x is the largest element of the vector being summed.

[Previous page](https://discourse.julialang.org/t/performance-of-norm-function/14709.md?page=1)
