# Why don't integer division errors occur in floating point division?

**URL:** https://discourse.julialang.org/t/why-dont-integer-division-errors-occur-in-floating-point-division/14345
**Category:** New to Julia
**Created:** [August 31, 2018, 3:12am UTC](https://discourse.julialang.org/t/why-dont-integer-division-errors-occur-in-floating-point-division/14345 "2018-08-31T03:12:02Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![hjohnston7](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@hjohnston7](https://discourse.julialang.org/u/hjohnston7)
#### Post date: [August 31, 2018, 3:12am UTC](https://discourse.julialang.org/t/why-dont-integer-division-errors-occur-in-floating-point-division/14345/1 "2018-08-31T03:12:02Z")

</div>

Hello!

I am currently making my way through the documentation, and I was wondering why the floating point division operator doesn’t throw the same errors as the integer division function. In the documentation, it says:

" Integer division (the `div` function) has two exceptional cases: dividing by zero, and dividing the lowest negative number ([`typemin`](https://docs.julialang.org/en/v1.0.0/base/base/#Base.typemin)) by -1. Both of these cases throw a [`DivideError`](https://docs.julialang.org/en/v1.0.0/base/base/#Core.DivideError). The remainder and modulus functions ( `rem` and `mod` ) throw a [`DivideError`](https://docs.julialang.org/en/v1.0.0/base/base/#Core.DivideError) when their second argument is zero."

When I do these same operations with the ‘/’ operator, I get:

> julia\> 1/0  
> Inf
> 
> julia\> typemin(Int64)/-1  
> 9.223372036854776e18

Why don’t these same errors get thrown when I do floating point division with the ‘/’ operator?

Edit:

I should have read a little bit further before posting. It says a little bit after that this is the result of the IEEE 754 standard.

---

<div class="post-metadata">

### Author: ![Guillermo\_C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/guillermo_c/32/209675_2.png) [@Guillermo\_C](https://discourse.julialang.org/u/Guillermo_C)
#### Post date: [June 3, 2024, 8:59am UTC](https://discourse.julialang.org/t/why-dont-integer-division-errors-occur-in-floating-point-division/14345/2 "2024-06-03T08:59:20Z")

</div>

The behavior of 1/0 seems clear to me by the IEEE 754 standard. However, I still don’t see why typemin(Int64)/-1 should produce a floating point value rather than throw an exception.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [June 3, 2024, 9:14am UTC](https://discourse.julialang.org/t/why-dont-integer-division-errors-occur-in-floating-point-division/14345/3 "2024-06-03T09:14:31Z")

</div>

As far as I can tell it produces the correct answer, so the behaviour makes sense:

```julia
julia> m = typemin(Int64)
-9223372036854775808

julia> (m/-1) == big(m)/big(-1)
true

```

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [June 3, 2024, 10:26am UTC](https://discourse.julialang.org/t/why-dont-integer-division-errors-occur-in-floating-point-division/14345/4 "2024-06-03T10:26:05Z")

</div>

Because the value can be represented using `Float64`, where it can’t using `Int64`.

---

<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: [June 3, 2024, 2:06pm UTC](https://discourse.julialang.org/t/why-dont-integer-division-errors-occur-in-floating-point-division/14345/6 "2024-06-03T14:06:01Z")

</div>

> [@hjohnston7](#):
>
> Why don’t these same errors get thrown when I do floating point division with the ‘/’ operator?

This was also discussed recently in another thread: [Division by zero runs without warning -\> complicates finding bugs - #2 by stevengj](https://discourse.julialang.org/t/division-by-zero-runs-without-warning-complicates-finding-bugs/113441/2)

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [June 3, 2024, 2:38pm UTC](https://discourse.julialang.org/t/why-dont-integer-division-errors-occur-in-floating-point-division/14345/7 "2024-06-03T14:38:49Z")

</div>

This is the oddest thread. The question was asked six years ago, then it was first responded to today.

---

<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: [June 3, 2024, 2:49pm UTC](https://discourse.julialang.org/t/why-dont-integer-division-errors-occur-in-floating-point-division/14345/8 "2024-06-03T14:49:02Z")

</div>

> [@BioTurboNick](#):
>
> This is the oddest thread. The question was asked six years ago, then it was first responded to today.

Yes, I didn’t notice that @Guillermo_C was necroposting on an ancient thread…

> [@Guillermo\_C](#):
>
> I still don’t see why `typemin(Int64)/-1` should produce a floating point

`integer / integer` in Julia is _always_ floating-point division. (Truncating integer division is represented by a different operation, [`div`](https://docs.julialang.org/en/v1/base/math/#Base.div).)
