# Problem in fitting (in function!)

**URL:** <https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785>\
**Category:** ROOT\
**Created:** [April 9, 2020, 8:05am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785 "2020-04-09T08:05:03Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 9, 2020, 10:20am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/5 "2020-04-09T10:20:29Z")

</div>

In your “fg” function, you blindly make calculations which may produce “±nan” and “±infinity” values.  
You could try:

```cpp
// if (TMath::IsNaN(valg) || TMath::IsNaN(-valg) || (valg == TMath::Infinity()) || (valg == -TMath::Infinity())) { std::cout << valg << std::endl; }
if (!((valg > -1000.) && (valg < 1000.))) valg = 0.; // a very brutal fix
return valg;

```

---

_[View the full topic](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785)._
