# Using an \`Int\` as a \`Num\`

**URL:** <https://discourse.julialang.org/t/using-an-int-as-a-num/110866>\
**Category:** General Usage\
**Tags:** symbolics\
**Created:** [February 28, 2024, 12:56am UTC](https://discourse.julialang.org/t/using-an-int-as-a-num/110866 "2024-02-28T00:56:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brombo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brombo/32/47867_2.png) [@brombo](https://discourse.julialang.org/u/brombo)\
**Post date:** [February 28, 2024, 12:56am UTC](https://discourse.julialang.org/t/using-an-int-as-a-num/110866/1 "2024-02-28T00:56:19Z")

</div>

I am using Symbolics.jl. I have a function `function f(a::Num,b::Num)::Num`, but in using it I want to use, sometimes -

```julia
@variables x, z
y = f(1,x)

```

as well as

```julia
@variables x, z
y = f(z,x)

```

but I get an error because `1` is not a `Num`. How can I get around this? Can I convert `1` to a `Num`. I wish to keep the arguments in `f` as they are now.

---

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [February 28, 2024, 1:07am UTC](https://discourse.julialang.org/t/using-an-int-as-a-num/110866/2 "2024-02-28T01:07:53Z")

</div>

I don’t know Symbolics, so please forgive me if this isn’t right, but I would guess that you can have the type of the argument be `Union{Num, Const}` or whatever type `1` is in the context of Symbolics.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [February 28, 2024, 1:11am UTC](https://discourse.julialang.org/t/using-an-int-as-a-num/110866/3 "2024-02-28T01:11:03Z")

</div>

You can remove `::Num` from the signature of `f`.

---

<div class="post-metadata">

**Author:** ![brianguenter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brianguenter/32/29519_2.png) [@brianguenter](https://discourse.julialang.org/u/brianguenter)\
**Post date:** [February 28, 2024, 1:12am UTC](https://discourse.julialang.org/t/using-an-int-as-a-num/110866/4 "2024-02-28T01:12:08Z")

</div>

You can convert 1 to a Num like this:

```julia
julia> Num(1)
1

julia> typeof(ans)
Num

```

---

<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:** [February 28, 2024, 1:32am UTC](https://discourse.julialang.org/t/using-an-int-as-a-num/110866/5 "2024-02-28T01:32:32Z")

</div>

> [@brombo](#):
>
> `f(a::Num,b::Num)::Num`

You are overconstraining your function arguments, and there is no need for the return-type declaration either. If you want to [declare argument types for dispatch or clarity](https://docs.julialang.org/en/v1/manual/functions/#Argument-type-declarations), you can declare your function as `f(a::Number, b::Number)`, for example, since both `Int` and `Num` are subtypes of `Number`. But it is perfectly fine to leave out the argument types entirely.

(Such type declarations typically do nothing for performance in Julia, contrary to popular misconception.)
