# Minor issue with if statement and may about types?

**URL:** <https://discourse.julialang.org/t/minor-issue-with-if-statement-and-may-about-types/109326>\
**Category:** New to Julia\
**Created:** [January 27, 2024, 2:20am UTC](https://discourse.julialang.org/t/minor-issue-with-if-statement-and-may-about-types/109326 "2024-01-27T02:20:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wooheon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wooheon/32/206569_2.png) [@Wooheon](https://discourse.julialang.org/u/Wooheon)\
**Post date:** [January 27, 2024, 2:20am UTC](https://discourse.julialang.org/t/minor-issue-with-if-statement-and-may-about-types/109326/1 "2024-01-27T02:20:48Z")

</div>

Hello, I just tried to make the following function.

```julia
function CRRA_bernoulli(ω::Float16,x::Int16)
    if ω == 1.00
        val = log( exp(1), x )
    else
        val = ( x / ( 1 - ω ) ) ^ ( 1 - ω )
    end
    return val
end

```

However, the result of putting ω = 1.0 showed the value 1.0.

```julia
CRRA_bernoulli(1.0,3850)

```

I do not understand why this is happening… Is ther e somebody who can help?

---

<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:** [January 27, 2024, 2:31am UTC](https://discourse.julialang.org/t/minor-issue-with-if-statement-and-may-about-types/109326/2 "2024-01-27T02:31:11Z")

</div>

As written, this doesn’t run since `1.0` isn’t a `Float16` and `3850` isn’t an `Int16`. You have another method defined for this function that is being called instead.

---

<div class="post-metadata">

**Author:** ![Wooheon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wooheon/32/206569_2.png) [@Wooheon](https://discourse.julialang.org/u/Wooheon)\
**Post date:** [January 27, 2024, 2:37am UTC](https://discourse.julialang.org/t/minor-issue-with-if-statement-and-may-about-types/109326/4 "2024-01-27T02:37:13Z")

</div>

I found out that as I changed 16 to 64 for all, the problem would be solved.  
I wonder if using 64 is a very typical thing to do. I was actually using 16 to save my memory.  
Thanks for the help, btw!

---

<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:** [January 27, 2024, 2:44am UTC](https://discourse.julialang.org/t/minor-issue-with-if-statement-and-may-about-types/109326/5 "2024-01-27T02:44:25Z")

</div>

if you wanted this to work for 16, you could by calling `CRRA_bernoulli(Float16(1.0),Int16(3850))` although you should be aware that on most CPUS it will be a lot slower. You also don’t need the type annotations at all. They don’t make things faster. If you want them for documentation purposes, I would recommend `::Real` and `::Integer` which will let you pass in arbitrary sized data.

---

<div class="post-metadata">

**Author:** ![Wooheon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wooheon/32/206569_2.png) [@Wooheon](https://discourse.julialang.org/u/Wooheon)\
**Post date:** [January 27, 2024, 3:01am UTC](https://discourse.julialang.org/t/minor-issue-with-if-statement-and-may-about-types/109326/6 "2024-01-27T03:01:53Z")

</div>

I thought if I described things in more detail, then the performance would improve.  
I never know about this. Thank you for the advice.

---

<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:** [January 27, 2024, 3:03am UTC](https://discourse.julialang.org/t/minor-issue-with-if-statement-and-may-about-types/109326/7 "2024-01-27T03:03:29Z")

</div>

Julia compiles a new assembly for your function for each combination of input types. types on function signatures only control dispatch.
