# A plea for int overflow checking as the default

**URL:** <https://discourse.julialang.org/t/a-plea-for-int-overflow-checking-as-the-default/3338>\
**Category:** Internals & Design\
**Tags:** question, proposal, integer-overflow\
**Created:** [April 22, 2017, 3:49pm UTC](https://discourse.julialang.org/t/a-plea-for-int-overflow-checking-as-the-default/3338 "2017-04-22T15:49:16Z")\
**Posts on this page:** 1\
**Showing post:** 67

<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:** [February 20, 2018, 12:22am UTC](https://discourse.julialang.org/t/a-plea-for-int-overflow-checking-as-the-default/3338/67 "2018-02-20T00:22:09Z")

</div>

@Jean_Michel this should get you through the night:

```julia
function collatz(lim)
           max = 1
           for i in 1:lim
            c = 0
            n = SafeUInt64(i)
            while n != 1
              if n&1==0
                n = fld(n,2) # <<< this is the only edit
              else      
                n = 3*n+1
              end
              c += 1
            end
            if c>max
              max = c
              println("at $i new max=$max")
            end
           end
       end
collatz (generic function with 1 method)

julia> collatz(1000)
at 3 new max=7
at 6 new max=8
at 7 new max=16
at 9 new max=19
at 18 new max=20
at 25 new max=23
at 27 new max=111
at 54 new max=112
at 73 new max=115
at 97 new max=118
at 129 new max=121
at 171 new max=124
at 231 new max=127
at 313 new max=130
at 327 new max=143
at 649 new max=144
at 703 new max=170
at 871 new max=178

```

---

_[View the full topic](https://discourse.julialang.org/t/a-plea-for-int-overflow-checking-as-the-default/3338)._
