# \#integer-overflow

**URL:** https://discourse.julialang.org/tag/integer-overflow/835.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Why is Julia the only one that doesn't overflow?](https://discourse.julialang.org/t/why-is-julia-the-only-one-that-doesnt-overflow/135758)

<div class="topic-metadata">

**Author:** [@cocoa1231](https://discourse.julialang.org/u/cocoa1231)\
**Replies:** 5\
**Last updated:** [February 20, 2026, 7:42pm UTC](https://discourse.julialang.org/t/why-is-julia-the-only-one-that-doesnt-overflow/135758 "2026-02-20T19:42:37Z")

</div>

I have the following tail recursive fibonacci function in zig, rust, julia and c. For some reason, only the Julia version doesn’t overflow. Why is that? fn fib(n: usize, p1: usize, p2: usize) -\> usize { if n \< 2 { …

---

## [InexactError vs OverflowError](https://discourse.julialang.org/t/inexacterror-vs-overflowerror/127108)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 3\
**Last updated:** [March 18, 2025, 7:05pm UTC](https://discourse.julialang.org/t/inexacterror-vs-overflowerror/127108 "2025-03-18T19:05:55Z")

</div>

I have a number type which throws when the result of a binary operation like + or \* is not representable in this type. I think InexactError is the right choice of exception, while OverflowError seems like a bad choice be…

---

## [Question about reduce?](https://discourse.julialang.org/t/question-about-reduce/82290)

<div class="topic-metadata">

**Author:** [@Raymond](https://discourse.julialang.org/u/Raymond)\
**Replies:** 3\
**Last updated:** [June 6, 2022, 2:47am UTC](https://discourse.julialang.org/t/question-about-reduce/82290 "2022-06-06T02:47:21Z")

</div>

What’s wrong with this? julia\> reduce(\*, 1:100) 0

---

## [Should large exponentials not yield Inf?](https://discourse.julialang.org/t/should-large-exponentials-not-yield-inf/81143)

<div class="topic-metadata">

**Author:** [@nil](https://discourse.julialang.org/u/nil)\
**Replies:** 15\
**Last updated:** [May 23, 2022, 12:41pm UTC](https://discourse.julialang.org/t/should-large-exponentials-not-yield-inf/81143 "2022-05-23T12:41:40Z")

</div>

I am wondering why some large exponentials yield wrong values, specifically always 1 or 0 julia\> 123^(456^789) 1 julia\> (0.1)^(456^789) 1.0 julia\> 456^789 0 This results in wrong values inside functions julia\> atan(…

---

## [Multiplication of 2 positive numbers gives a negative product](https://discourse.julialang.org/t/multiplication-of-2-positive-numbers-gives-a-negative-product/80323)

<div class="topic-metadata">

**Author:** [@Brinkhuis](https://discourse.julialang.org/u/Brinkhuis)\
**Replies:** 11\
**Last updated:** [May 1, 2022, 4:25pm UTC](https://discourse.julialang.org/t/multiplication-of-2-positive-numbers-gives-a-negative-product/80323 "2022-05-01T16:25:32Z")

</div>

In Julia 1.7.2 multiplication of 3037000691 and 3037000693 returns the negative product -9223370870501072753. The product I expected is 9223373203208478863. function m(a::BigInt, b::BigInt)::BigInt a \* b end This f…

---

## [Type computation: numerical type with twice more bits](https://discourse.julialang.org/t/type-computation-numerical-type-with-twice-more-bits/77000)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 3\
**Last updated:** [February 24, 2022, 9:42am UTC](https://discourse.julialang.org/t/type-computation-numerical-type-with-twice-more-bits/77000 "2022-02-24T09:42:47Z")

</div>

I’m trying to write a generic function accepting two Integers as arguments. The function will need a local variable storing the product of the two integers. So if the functions arguments are of type Int16, the local vari…

---

## [X.^2 - how can something so basic be so wrong](https://discourse.julialang.org/t/x-2-how-can-something-so-basic-be-so-wrong/76052)

<div class="topic-metadata">

**Author:** [@alex-s-gardner](https://discourse.julialang.org/u/alex-s-gardner)\
**Replies:** 2\
**Last updated:** [February 9, 2022, 12:31am UTC](https://discourse.julialang.org/t/x-2-how-can-something-so-basic-be-so-wrong/76052 "2022-02-09T00:31:12Z")

</div>

Working with Int16 data I’m getting negative values when squaring data: a = -750; a^2 562500 a = Int16(a); a^2 -27324 I get that Int16(a)^2 produces a value that is out of the range of an Int16 but I don’t get why…

---

## [Long Math Operation result is 0, In Python isn't](https://discourse.julialang.org/t/long-math-operation-result-is-0-in-python-isnt/73720)

<div class="topic-metadata">

**Author:** [@Jogrefer](https://discourse.julialang.org/u/Jogrefer)\
**Replies:** 7\
**Last updated:** [January 2, 2022, 7:20pm UTC](https://discourse.julialang.org/t/long-math-operation-result-is-0-in-python-isnt/73720 "2022-01-02T19:20:15Z")

</div>

Hi everyone :slight\_smile: Well, I’m new in this in general and just testing the REPL with random numbers. Why this is happening and what I’ve to learn previous to declare operations like this one? In Julia (1.7.0): n…

---

## [A plea for int overflow checking as the default](https://discourse.julialang.org/t/a-plea-for-int-overflow-checking-as-the-default/3338)

<div class="topic-metadata">

**Author:** [@nickeubank](https://discourse.julialang.org/u/nickeubank)\
**Replies:** 79\
**Last updated:** [December 17, 2021, 2:18am UTC](https://discourse.julialang.org/t/a-plea-for-int-overflow-checking-as-the-default/3338 "2021-12-17T02:18:36Z")

</div>

Hello JuliaLang Community! I am a social scientist making his way from the Python ecosystem (mostly numpy & pandas) to Julia, and have in general been delighted by the language – concise, generally quite readable, and p…

---

## [OverflowContexts.jl - Fine control of integer overflow checking](https://discourse.julialang.org/t/overflowcontexts-jl-fine-control-of-integer-overflow-checking/72273)

<div class="topic-metadata">

**Author:** [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Replies:** 1\
**Last updated:** [December 4, 2021, 6:54pm UTC](https://discourse.julialang.org/t/overflowcontexts-jl-fine-control-of-integer-overflow-checking/72273 "2021-12-04T18:54:14Z")

</div>

Spurred on by a new gripe on Slack about an overflowing integer math issue, I revisited my test package for trying to allow Julia to switch between checked an unchecked arithmetic. I realized it essentially already provi…

---

## [Potential solution to the overflow problem; 64-bit considered harmful, 32- or 21-bit better](https://discourse.julialang.org/t/potential-solution-to-the-overflow-problem-64-bit-considered-harmful-32-or-21-bit-better/69918)

<div class="topic-metadata">

**Author:** [@Palli](https://discourse.julialang.org/u/Palli)\
**Replies:** 6\
**Last updated:** [October 18, 2021, 8:28pm UTC](https://discourse.julialang.org/t/potential-solution-to-the-overflow-problem-64-bit-considered-harmful-32-or-21-bit-better/69918 "2021-10-18T20:28:05Z")

</div>

We can implement FastIntegers.jl, faster than the current default Int64 and eliminate overflows from the language by leveraging Julia’s type system, and no hardware support is needed. As a package it of course doesn’t ch…

---

## [Discussion about integer overflow](https://discourse.julialang.org/t/discussion-about-integer-overflow/69627)

<div class="topic-metadata">

**Author:** [@viraltux](https://discourse.julialang.org/u/viraltux)\
**Replies:** 188\
**Last updated:** [October 15, 2021, 5:02pm UTC](https://discourse.julialang.org/t/discussion-about-integer-overflow/69627 "2021-10-15T17:02:21Z")

</div>

Yes, it is a limitation but I would not call it big since we could use BigInt if Int64 is not enough and an overflow is something we can catch. I find more worrying this: \> julia\> 1 / 10^20000 \> Inf I’d rather have …

---

## [SaferIntegers v3](https://discourse.julialang.org/t/saferintegers-v3/68013)

<div class="topic-metadata">

**Author:** [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Replies:** 2\
**Last updated:** [September 11, 2021, 2:37am UTC](https://discourse.julialang.org/t/saferintegers-v3/68013 "2021-09-11T02:37:39Z")

</div>

SaferIntegers.jl version 3 exists. The exported abstract types SafeInteger, SafeSigned, SafeUnsigned are now defined as originally intended – Julia’s advancement, the active pursuit of consistant type abstractions, mad…

---

## [Bug? parse(Integer, ...) calls typemax](https://discourse.julialang.org/t/bug-parse-integer-calls-typemax/67252)

<div class="topic-metadata">

**Author:** [@Mark\_Nahabedian](https://discourse.julialang.org/u/Mark_Nahabedian)\
**Replies:** 15\
**Last updated:** [August 29, 2021, 1:47pm UTC](https://discourse.julialang.org/t/bug-parse-integer-calls-typemax/67252 "2021-08-29T13:47:06Z")

</div>

Is this a bug parse(Integer, "1234567890987654321234567890") ERROR: MethodError: no method matching typemax(::Type{Integer}) Closest candidates are: typemax(!Matched::Union{Dates.DateTime, Type{Dates.DateTime}}) at C:…

---

## [Large sum returns negative numbers in julia](https://discourse.julialang.org/t/large-sum-returns-negative-numbers-in-julia/49032)

<div class="topic-metadata">

**Author:** [@dashanan](https://discourse.julialang.org/u/dashanan)\
**Replies:** 5\
**Last updated:** [October 26, 2020, 6:55pm UTC](https://discourse.julialang.org/t/large-sum-returns-negative-numbers-in-julia/49032 "2020-10-26T18:55:22Z")

</div>

hello , i am trying to do a counter for some problem I am having, but while I was testing I see that Julia was returning negative numbers after some time, I have no idea why this is happening, now to check that, i ha…

---

## [Why is 2^63 negative?](https://discourse.julialang.org/t/why-is-2-63-negative/48513)

<div class="topic-metadata">

**Author:** [@timvink](https://discourse.julialang.org/u/timvink)\
**Replies:** 16\
**Last updated:** [October 19, 2020, 7:10pm UTC](https://discourse.julialang.org/t/why-is-2-63-negative/48513 "2020-10-19T19:10:57Z")

</div>

Hi :wave: Making my first steps into julia, coming from R and python. Following the getting started guide, I noticed the following: 2^62 # 4611686018427387904 2^63 # \<--- This is negative? # -9223372036854775808 2^63 \> …

---

## [The speed of light is an integer. Why should we care?](https://discourse.julialang.org/t/the-speed-of-light-is-an-integer-why-should-we-care/40108)

<div class="topic-metadata">

**Author:** [@gevis](https://discourse.julialang.org/u/gevis)\
**Replies:** 78\
**Last updated:** [September 7, 2020, 3:55pm UTC](https://discourse.julialang.org/t/the-speed-of-light-is-an-integer-why-should-we-care/40108 "2020-09-07T15:55:35Z")

</div>

Since 1983, the speed of light is defined to be exactly equal to 299,792,458 meters per second. So, it seems natural to define it as an integer while doing some culculations with Julia, for example, to calculate a Planck…

---

## [Math operation known issue? a^b](https://discourse.julialang.org/t/math-operation-known-issue-a-b/38839)

<div class="topic-metadata">

**Author:** [@Rougem](https://discourse.julialang.org/u/Rougem)\
**Replies:** 11\
**Last updated:** [May 6, 2020, 9:17am UTC](https://discourse.julialang.org/t/math-operation-known-issue-a-b/38839 "2020-05-06T09:17:20Z")

</div>

Today is my first day with Julia. While, working with the command line I realized that some results were negative and wrong. I am new, so if I made a mistake please let me know. What is wrong? Thanks a lot! Issue:

---

## [Tonight I hated julia, REPL and overflows](https://discourse.julialang.org/t/tonight-i-hated-julia-repl-and-overflows/34884)

<div class="topic-metadata">

**Author:** [@benibilme](https://discourse.julialang.org/u/benibilme)\
**Replies:** 64\
**Last updated:** [March 14, 2020, 8:43pm UTC](https://discourse.julialang.org/t/tonight-i-hated-julia-repl-and-overflows/34884 "2020-03-14T20:43:58Z")

</div>

Hello, I am a newcommer in Julia. I have read almost entire never ending boring manual, read a couple books, watched some videos, and practicing probability theory with julia with much enthusiasm. I spend great of time …

---

## [Mean of integers overflows - bug or expected behaviour?](https://discourse.julialang.org/t/mean-of-integers-overflows-bug-or-expected-behaviour/34767)

<div class="topic-metadata">

**Author:** [@Mikhail\_Kagalenko](https://discourse.julialang.org/u/Mikhail_Kagalenko)\
**Replies:** 94\
**Last updated:** [March 3, 2020, 2:44am UTC](https://discourse.julialang.org/t/mean-of-integers-overflows-bug-or-expected-behaviour/34767 "2020-03-03T02:44:51Z")

</div>

The function mean(), when used on Int inputs, returns a float result. However, it may silently overflow on integer arithmetic. julia\> mean(\[1,1\]\*typemax(Int)) -1 Maintainer of Statistics.jl closed the issue, saying t…

---

## [Integer overflow in cumprod (cumulative product) output](https://discourse.julialang.org/t/integer-overflow-in-cumprod-cumulative-product-output/33037)

<div class="topic-metadata">

**Author:** [@1634](https://discourse.julialang.org/u/1634)\
**Replies:** 4\
**Last updated:** [January 6, 2020, 10:45pm UTC](https://discourse.julialang.org/t/integer-overflow-in-cumprod-cumulative-product-output/33037 "2020-01-06T22:45:14Z")

</div>

The cumulative product vector of a series of linear positive numbers (show in plot(cump1) ) contains negative num and zeros(in plot(cump2)). I checked available documentations carefully and still was in dark. twoNmu=1;n…

---

## [Julia messes up integer exponents?](https://discourse.julialang.org/t/julia-messes-up-integer-exponents/20773)

<div class="topic-metadata">

**Author:** [@MrRobot](https://discourse.julialang.org/u/MrRobot)\
**Replies:** 106\
**Last updated:** [February 21, 2019, 11:59pm UTC](https://discourse.julialang.org/t/julia-messes-up-integer-exponents/20773 "2019-02-21T23:59:02Z")

</div>

I was using avogadro’s number in a calculation and couldn’t figure out why the results were not matching my matlab or python code… Turns out using integers as exponents gets you in trouble in Julia?They start off innoce…

---

## [Allowing integers to overflow to 0](https://discourse.julialang.org/t/allowing-integers-to-overflow-to-0/17394)

<div class="topic-metadata">

**Author:** [@wherrera](https://discourse.julialang.org/u/wherrera)\
**Replies:** 3\
**Last updated:** [November 11, 2018, 4:24am UTC](https://discourse.julialang.org/t/allowing-integers-to-overflow-to-0/17394 "2018-11-11T04:24:08Z")

</div>

I’ve come across a place where allowing a UInt8 to overflow to 0 on adding 1 is the proper behavior. Is there something like a decorator macro to allow the overflow and not get the overflow error with adding 1 to 255::U…

---

## [Help to create a macro do avoid integer overflow](https://discourse.julialang.org/t/help-to-create-a-macro-do-avoid-integer-overflow/11354)

<div class="topic-metadata">

**Author:** [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Replies:** 14\
**Last updated:** [June 2, 2018, 5:43pm UTC](https://discourse.julialang.org/t/help-to-create-a-macro-do-avoid-integer-overflow/11354 "2018-06-02T17:43:16Z")

</div>

Hi guys! I need help to create a macro to do the following: On every integer operation, check if overflow will happen. If it does, then promote the arguments to integer representations with higher number of bits. I d…

---

## [Question about abs()](https://discourse.julialang.org/t/question-about-abs/10198)

<div class="topic-metadata">

**Author:** [@s920128](https://discourse.julialang.org/u/s920128)\
**Replies:** 6\
**Last updated:** [April 6, 2018, 2:34pm UTC](https://discourse.julialang.org/t/question-about-abs/10198 "2018-04-06T14:34:22Z")

</div>

I use abs(-9223372036854775808) in Julia but output is -9223372036854775808 Is this a bug?

---

## [How to throw an error on value overflow?](https://discourse.julialang.org/t/how-to-throw-an-error-on-value-overflow/3408)

<div class="topic-metadata">

**Author:** [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Replies:** 2\
**Last updated:** [May 7, 2017, 9:38pm UTC](https://discourse.julialang.org/t/how-to-throw-an-error-on-value-overflow/3408 "2017-05-07T21:38:54Z")

</div>

For example, in Int64: 10^21 returns 3875820019684212736 How do you turn off rollover and just throw an error instead?

---

## [Overflow behaviour - how to explain](https://discourse.julialang.org/t/overflow-behaviour-how-to-explain/996)

<div class="topic-metadata">

**Author:** [@Balinus](https://discourse.julialang.org/u/Balinus)\
**Replies:** 9\
**Last updated:** [December 21, 2016, 6:15pm UTC](https://discourse.julialang.org/t/overflow-behaviour-how-to-explain/996 "2016-12-21T18:15:13Z")

</div>

Hello, I’m preparing a little introductory presentation for my team on Julia. I’d like to do some slides on where people should be careful. Overflow bahaviour is certainly one of them imho. I just don’t know how to expl…
