# 1 is not a UInt

**URL:** <https://discourse.julialang.org/t/1-is-not-a-uint/72578>\
**Category:** New to Julia\
**Created:** [December 4, 2021, 2:36pm UTC](https://discourse.julialang.org/t/1-is-not-a-uint/72578 "2021-12-04T14:36:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dodoplus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dodoplus/32/30148_2.png) [@dodoplus](https://discourse.julialang.org/u/dodoplus)\
**Post date:** [December 4, 2021, 2:36pm UTC](https://discourse.julialang.org/t/1-is-not-a-uint/72578/1 "2021-12-04T14:36:08Z")

</div>

Hi,

As `typeof(1) == Int64`, we have `1 isa UInt == false`

However, this makes it difficult to pass a default value:

```julia
f(x::UInt = 1) = 2

f()
# MethodError: no method matching f(::Int64)

```

Sure, I can define:

```julia
f(x::UInt = UInt(1)) = 2

```

but it’s ugly…

DD

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 4, 2021, 2:49pm UTC](https://discourse.julialang.org/t/1-is-not-a-uint/72578/2 "2021-12-04T14:49:08Z")

</div>

It would be a really bad idea for `1` to default to `UInt` 😱

I would not expect this to change. Otherwise `1 - 3` would be type unstable or have integer underflow.

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [December 4, 2021, 2:50pm UTC](https://discourse.julialang.org/t/1-is-not-a-uint/72578/3 "2021-12-04T14:50:23Z")

</div>

There is a literal syntax for `UInt64`, but it is more verbose than typing `UInt(1)`:

```julia
julia> 0x0000000000000001 == UInt(1)
true

```

---

<div class="post-metadata">

**Author:** ![dodoplus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dodoplus/32/30148_2.png) [@dodoplus](https://discourse.julialang.org/u/dodoplus)\
**Post date:** [December 4, 2021, 2:56pm UTC](https://discourse.julialang.org/t/1-is-not-a-uint/72578/4 "2021-12-04T14:56:24Z")

</div>

True…  
But the issue here is handling of default parameters.  
Why not automatically convert those? They are constants, so this can be done at compile time.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 4, 2021, 2:59pm UTC](https://discourse.julialang.org/t/1-is-not-a-uint/72578/5 "2021-12-04T14:59:08Z")

</div>

Yeah, open an issue for conversion of literals in defaults. That would be a little magical, but that could happen in that specific context (reminiscent of `literal_pow`). But the general topic here, `1 is not a UInt`, I think is a done deal.

---

<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:** [December 4, 2021, 5:12pm UTC](https://discourse.julialang.org/t/1-is-not-a-uint/72578/6 "2021-12-04T17:12:48Z")

</div>

> [@ChrisRackauckas](#):
>
> Yeah, open an issue for conversion of literals in defaults.

This was already discussed. See: [dispatch behavior of optional arguments · Issue #7357 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/7357)
