# Division by zero runs without warning -\> complicates finding bugs

**URL:** <https://discourse.julialang.org/t/division-by-zero-runs-without-warning-complicates-finding-bugs/113441>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [April 24, 2024, 12:33pm UTC](https://discourse.julialang.org/t/division-by-zero-runs-without-warning-complicates-finding-bugs/113441 "2024-04-24T12:33:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 24, 2024, 12:43pm UTC](https://discourse.julialang.org/t/division-by-zero-runs-without-warning-complicates-finding-bugs/113441/2 "2024-04-24T12:43:42Z")

</div>

> [@lisapisa](#):
>
> How do you feel about this? Am I missing a very good reason for this to be the default behaviour?

`/` in Julia is floating-point division (unlike C/C++), and the [IEEE 754 standard](https://en.wikipedia.org/wiki/IEEE_754) says that floating-point division of a nonzero (and non-nan) ±value by +0 gives ±Inf. (Though it would be nice to have a way to [trap fp exceptions (julia issue #27705)](https://github.com/JuliaLang/julia/issues/27705).)

In C/C++, you will also get `Inf` with floating-point division like `100/0.0`. It’s just that `100/0` in C/C++ is truncated integer division (`3/2 == 1` in C/C++), not floating-point division, analogous to [Julia’s `div`](https://docs.julialang.org/en/v1/base/math/#Base.div):

```jl
julia> div(100,0)
ERROR: DivideError: integer division error

```

which also throws an error.

Even in Python, this produces `inf` with NumPy:

```julia
>>> np.int64(100)/0
inf

```

I’m guessing that the reason `100/0` doesn’t produce `inf` in Python is a legacy of Python2, where `integer / integer` was truncated integer division like C/C++, not floating-point division.

In other languages where `/` is floating-point division, the examples I can find also typically seem to follow the IEEE 754 behavior of producing `Inf` from division by 0, similar to Julia. For example, R, Javascript, Matlab …

---

_[View the full topic](https://discourse.julialang.org/t/division-by-zero-runs-without-warning-complicates-finding-bugs/113441)._
