# Normalizing a vector to sum to one does not work?

**URL:** <https://discourse.julialang.org/t/normalizing-a-vector-to-sum-to-one-does-not-work/69560>\
**Category:** General Usage\
**Tags:** numbers, vector\
**Created:** [October 11, 2021, 11:27am UTC](https://discourse.julialang.org/t/normalizing-a-vector-to-sum-to-one-does-not-work/69560 "2021-10-11T11:27:13Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [October 11, 2021, 12:33pm UTC](https://discourse.julialang.org/t/normalizing-a-vector-to-sum-to-one-does-not-work/69560/7 "2021-10-11T12:33:19Z")

</div>

The big limitation here is the rational numbers overflow in ways potentially more surprising than floating point numbers:

```julia
julia> x = 1//10
1//10

julia> typeof(x)
Rational{Int64}

julia> for i in 1:1_000
           x *= 1//10
           println((i, x))
           end
(1, 1//100)
(2, 1//1000)
(3, 1//10000)
(4, 1//100000)
(5, 1//1000000)
(6, 1//10000000)
(7, 1//100000000)
(8, 1//1000000000)
(9, 1//10000000000)
(10, 1//100000000000)
(11, 1//1000000000000)
(12, 1//10000000000000)
(13, 1//100000000000000)
(14, 1//1000000000000000)
(15, 1//10000000000000000)
(16, 1//100000000000000000)
(17, 1//1000000000000000000)
ERROR: OverflowError: 1000000000000000000 * 10 overflowed for type Int64
Stacktrace:
 [1] throw_overflowerr_binaryop(op::Symbol, x::Int64, y::Int64)
   @ Base.Checked ./checked.jl:154
 [2] checked_mul
   @ ./checked.jl:288 [inlined]
 [3] *(x::Rational{Int64}, y::Rational{Int64})
   @ Base ./rational.jl:334
 [4] top-level scope
   @ ./REPL[3]:2

```

This is actually part of the general problem – given a fixed number of bits, you can trade off exactness for range or range for exactness. Rational numbers have less range, but are exact; floating point have much larger range but are not exact.

---

_[View the full topic](https://discourse.julialang.org/t/normalizing-a-vector-to-sum-to-one-does-not-work/69560)._
