# Differences in MATLAB's versus Julia's beta(x, y) for large x or y?

**URL:** https://discourse.julialang.org/t/differences-in-matlabs-versus-julias-beta-x-y-for-large-x-or-y/60138
**Category:** General Usage
**Tags:** specialfunctions
**Created:** [April 28, 2021, 12:45am UTC](https://discourse.julialang.org/t/differences-in-matlabs-versus-julias-beta-x-y-for-large-x-or-y/60138 "2021-04-28T00:45:43Z")
**Posts on this page:** 1
**Showing post:** 7

<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: [April 28, 2021, 1:51pm UTC](https://discourse.julialang.org/t/differences-in-matlabs-versus-julias-beta-x-y-for-large-x-or-y/60138/7 "2021-04-28T13:51:07Z")

</div>

I _think_ Julia’s answer is closer to correct, but with this large of a number it’s easy to blow up or hit a catastrophic cancellation. To take this back one step, a naive definition for beta is

\beta(p, q) = \frac{\Gamma(p) \Gamma(q)}{\Gamma(p+q)}

You wouldn’t want to use this implementation in the real world, though, because those intermediate values are _huge_. Like 10^{472392288679098} huge. So I’m quite certain this _isn’t_ the implementation in either language.

```julia
julia> gamma(3.6e13)
Inf

```

But, hey, we can opt into higher precision floating point here:

```julia
julia> gamma(big(3.6e13))
7.882861104028365451673058070377064242970022825665897715265241972922672893761775e+472392288679098

julia> p = big(3.6e13)
3.6e+13

julia> q = 1/big(0.563483398)+1
2.774675178628776489804929213602311938188089959295862682297487944939957397047059

julia> gamma(p)*gamma(q)/gamma(p+q)
3.989149176788555366691087811957298867890005562542321569109120632926257477147039e-38

julia> beta(p, q)
3.989149176788555366691087811957298867890005562542321569109120643773484257104723e-38

```

So I’m not a numericist, but I think this is looking pretty good.

---

_[View the full topic](https://discourse.julialang.org/t/differences-in-matlabs-versus-julias-beta-x-y-for-large-x-or-y/60138)._
