# Error for 396^n

**URL:** <https://discourse.julialang.org/t/error-for-396-n/110099>\
**Category:** General Usage\
**Tags:** bug, error\
**Created:** [February 12, 2024, 12:22pm UTC](https://discourse.julialang.org/t/error-for-396-n/110099 "2024-02-12T12:22:51Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [February 12, 2024, 12:59pm UTC](https://discourse.julialang.org/t/error-for-396-n/110099/5 "2024-02-12T12:59:51Z")

</div>

The power ^ operator is the one thing I would want to change in Julia, even power of 3 can be a problem, see linked issue. For a^b it’s rather unsafe, unless a and/or b are floating point numbers, or `big` integers, not even Int128 type is safe.

All math operators can overflow, even + (and \* and -), except /, and this may come as a surprise, except to users of most languages, such as C and C++, i.e. fast languages.

```julia
julia> typemax(Int128)+1
-170141183460469231731687303715884105728

```

In some sense that IS a correct result, i.e. ALL operators (expect `/` since it divides with a Float64 result) return modular math results, and they are correct when defined that way, but unexpected definition for many or most users. And for power, I think maybe never a good definition, while ok when you do not actually overflow, as with all the other operators.

So why do I only want to change `^`? Because the problem is more apparent there (it’s the one operator that is really dangerous, much more than the other), and with Int64 type (the default Int type on 64-platforms), +, -, are in practice not a worry, and \* also rarely, though more often.

[If you divide by 2, you get the correct _exact_ result at least half the time, but if you divide by e.g. 3, you _never_ get the correct _exact_ result, unless you use `Rational`s, and that is a problem for any language (except maybe Raku/Perl 6 that may default to rationals, or does it not?). And even the rationals need to be of the BigInt type to guard against overflow. So with math you are screwed in pretty much any language, unless you opt into non-defaults, take care. Why do I mention thi? Because correct math vs fast math is a trade-off in any language, even a trade-off between approximately correct and fast.]

> [@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/7):
>
> It is an unfortunate trade-off between performance and safety. However, I think that the decision to default to fast integers in Julia is correct, most of the time there is no overflow risk. However, it would be great if future CPUs would have hardware-support for zero-cost overflow safe integers.

---

_[View the full topic](https://discourse.julialang.org/t/error-for-396-n/110099)._
