# Why doesn't 1//0 throw an error?

**URL:** <https://discourse.julialang.org/t/why-doesnt-1-0-throw-an-error/131354>\
**Category:** Numerics\
**Created:** [August 5, 2025, 2:05am UTC](https://discourse.julialang.org/t/why-doesnt-1-0-throw-an-error/131354 "2025-08-05T02:05:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![HMegh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hmegh/32/216684_2.png) [@HMegh](https://discourse.julialang.org/u/HMegh)\
**Post date:** [August 5, 2025, 2:05am UTC](https://discourse.julialang.org/t/why-doesnt-1-0-throw-an-error/131354/1 "2025-08-05T02:05:05Z")

</div>

Hi, I have noticed that `1//0` does not throw any errors, which is a bit unexpected. Even more, `inv(0//1)` is `1//0`. On the other hand, `0//0` throws an argument error (understandably). Is this the intended behavior?

My current understanding is that `1//0` mimics the behavior of `Inf`. However, the main difference is that `0*Inf` is a NaN, whereas `0*(1//0)` throws an error. I encountered this situation when looking at this [issue](https://github.com/JuliaArrays/StaticArrays.jl/issues/1308) in StaticArrays.jl, where `A=@SMatrix zeros(5,5);det(A)` works fine and `A=@SMatrix zeros(Rational,5,5);det(A)` does not for the reason stated above.

---

<div class="post-metadata">

**Author:** ![technocrat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/technocrat/32/220947_2.png) [@technocrat](https://discourse.julialang.org/u/technocrat)\
**Post date:** [August 5, 2025, 2:16am UTC](https://discourse.julialang.org/t/why-doesnt-1-0-throw-an-error/131354/2 "2025-08-05T02:16:04Z")

</div>

Come down to pure laziness, but in a good way.

Start with the rationals.

```julia-auto
struct Rational{T<:Integer} <: Real
    num::T
    den::T
end

```

So

`typeof(1//00)` is `Rational(1, 0)` **but** no error is immediately thrown. That’s the job of any function to evaluate and decide how to treat it.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [August 5, 2025, 2:37am UTC](https://discourse.julialang.org/t/why-doesnt-1-0-throw-an-error/131354/3 "2025-08-05T02:37:21Z")

</div>

No. It was intentional, with analogies to floating point.

> <https://github.com/JuliaLang/julia/issues/20349#issuecomment-276454366>
>
> \`\`\`julia
> julia\> 1//0
> 1//0
> 
> julia\> div(1,0)
> ERROR: DivideError: integer divi…sion error
> Stacktrace:
> \[1\] div(::Int64, ::Int64) at ./int.jl:144
> \`\`\`
> 
> Should \`1//0\` also error out?

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [August 5, 2025, 3:45am UTC](https://discourse.julialang.org/t/why-doesnt-1-0-throw-an-error/131354/4 "2025-08-05T03:45:28Z")

</div>

> `0*Inf` is a NaN, whereas `0*(1//0)` throws an error

If `1//0` is intended to be analogous to floating point `Inf`, then this seems like a place where that analogy is broken.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [August 5, 2025, 3:51am UTC](https://discourse.julialang.org/t/why-doesnt-1-0-throw-an-error/131354/5 "2025-08-05T03:51:49Z")

</div>

That is the intent. It works out such that Inf falls out naturally from the rest of the rational math, while NaN doesn’t.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [August 5, 2025, 4:21am UTC](https://discourse.julialang.org/t/why-doesnt-1-0-throw-an-error/131354/6 "2025-08-05T04:21:30Z")

</div>

`1//0` being analogous to +Inf doesn’t mean `Rational` has to comply with IEEE 754, and `num` and `den` doesn’t have room for NaNs. `Rational` also throws an error upon `num` overflow instead of going to ±Inf (I suppose `1//0` and `-1//0` for `Rational`), and `Integer` doesn’t (usually) have a negative zero.
