# NaN returned by gauss()

**URL:** <https://discourse.julialang.org/t/nan-returned-by-gauss/68260>\
**Category:** Numerics\
**Tags:** quadgk\
**Created:** [September 16, 2021, 1:21pm UTC](https://discourse.julialang.org/t/nan-returned-by-gauss/68260 "2021-09-16T13:21:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![trg818](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trg818/32/219149_2.png) [@trg818](https://discourse.julialang.org/u/trg818)\
**Post date:** [September 16, 2021, 1:21pm UTC](https://discourse.julialang.org/t/nan-returned-by-gauss/68260/1 "2021-09-16T13:21:41Z")

</div>

I’m using the function `gauss()` from `QuadGK` in order to calculate a non-adaptive quadrature and am irritated about the appearance of `NaN` beyond a certain `N`. Specifically, `gauss(1093,38.68598671891722,150000.0)` returns an array that is partly populated with `NaN`, whereas `gauss(1092,38.68598671891722,150000.0)` seems to be ok. Why is this, and is it supposed to be this way? A proper warning or error message would be more helpful than just returning `NaN` and waiting with the crash until they are used.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [September 16, 2021, 1:27pm UTC](https://discourse.julialang.org/t/nan-returned-by-gauss/68260/2 "2021-09-16T13:27:51Z")

</div>

Can you use FastGaussQuadrature.jl?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [September 16, 2021, 2:12pm UTC](https://discourse.julialang.org/t/nan-returned-by-gauss/68260/3 "2021-09-16T14:12:51Z")

</div>

Is using BigFloats an option?  
`gauss(BigFloat, 1093, 38.68598671891722, 150000.0) `

---

<div class="post-metadata">

**Author:** ![trg818](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trg818/32/219149_2.png) [@trg818](https://discourse.julialang.org/u/trg818)\
**Post date:** [September 16, 2021, 4:33pm UTC](https://discourse.julialang.org/t/nan-returned-by-gauss/68260/4 "2021-09-16T16:33:04Z")

</div>

Thanks for pointing me to this extra option. Yes, I tried it with `N=1500` and it did work, although the use of BigFloats seems to make the calculation noticeably slower.

---

<div class="post-metadata">

**Author:** ![trg818](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trg818/32/219149_2.png) [@trg818](https://discourse.julialang.org/u/trg818)\
**Post date:** [September 16, 2021, 4:41pm UTC](https://discourse.julialang.org/t/nan-returned-by-gauss/68260/5 "2021-09-16T16:41:09Z")

</div>

Yes and no, I guess. Yes, because it seems that the `NaN`s don’t show up. However, when applying the nodes and weights from it (generated with gausschebyshev, because my interval is finite) to my main calculation, where the integration appears, with changing bounds, in a time-stepping loop, the calculation seems to hang for some reason, although I don’t think I made a mistake in the remapping of the interval (which I understand is for some reason not included in FastGaussQuadrature.jl).

---

<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:** [September 16, 2021, 6:02pm UTC](https://discourse.julialang.org/t/nan-returned-by-gauss/68260/6 "2021-09-16T18:02:33Z")

</div>

> [@trg818](#):
>
> Specifically, `gauss(1093,38.68598671891722,150000.0)` returns an array that is partly populated with `NaN` ,

This is a bug; it looks like an underflow problem in my Newton iteration. I’ll push a fix shortly.

---

<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:** [September 16, 2021, 7:33pm UTC](https://discourse.julialang.org/t/nan-returned-by-gauss/68260/7 "2021-09-16T19:33:37Z")

</div>

> [@trg818](#):
>
> I’m using the function `gauss()` from `QuadGK` in order to calculate a non-adaptive quadrature and am irritated about the appearance of `NaN` beyond a certain `N` .

The bug is fixed in the latest version (2.4.2) of QuadGK:

```julia-auto
julia> all.(isfinite, gauss(1093,38.68598671891722,150000.0))
(true, true)

```

---

<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:** [September 17, 2021, 12:23am UTC](https://discourse.julialang.org/t/nan-returned-by-gauss/68260/8 "2021-09-17T00:23:11Z")

</div>

A post was split to a new topic: [Problem upgrading GR package](https://discourse.julialang.org/t/problem-upgrading-gr-package/68290)
