# Support for signaling NaNs?

**URL:** <https://discourse.julialang.org/t/support-for-signaling-nans/75571>\
**Category:** General Usage\
**Tags:** question, nan\
**Created:** [February 1, 2022, 11:09am UTC](https://discourse.julialang.org/t/support-for-signaling-nans/75571 "2022-02-01T11:09:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephancb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephancb/32/14243_2.png) [@stephancb](https://discourse.julialang.org/u/stephancb)\
**Post date:** [February 1, 2022, 11:09am UTC](https://discourse.julialang.org/t/support-for-signaling-nans/75571/1 "2022-02-01T11:09:52Z")

</div>

In Julia generally `missing` is favored over `NaN`, among other because `NaN` work only for floating point types, and [because the origin of `NaN`s can be hard to trace once they have infected the data.](https://discourse.julialang.org/t/how-to-replace-all-values-in-an-array-with-missing-values/75467/26)

However, IEEE745 has also signaling NaNs, [supported in C++11](https://en.cppreference.com/w/cpp/numeric/fenv), but not in Julia at least not “officially”. I found [this discussion](https://github.com/JuliaLang/julia/issues/27705) where also a solution for Linux/x86 is outlined. A problem seems to be that LLVM (still?) does not support hardware exceptions? Is there any updated “insider” information which I have not been able to find? A package for at least Linux/x86?

Having worked with various hardware that signals when something is wrong I presume that the signaling NaNs would be a good and efficient solution in many cases when computations are within floating points.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [November 19, 2024, 3:47pm UTC](https://discourse.julialang.org/t/support-for-signaling-nans/75571/2 "2024-11-19T15:47:08Z")

</div>

Code for “add floating point environment to task state” issue has been added (and that issue closed): [add fenv cache to task struct by simonbyrne · Pull Request #51288 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/51288)

See also open issue, and code there:

> <https://github.com/JuliaLang/julia/issues/27705#issuecomment-2267560310>
>
> Some languages and compilers allow trapping of floating point exceptions, e.g. g…fortran -ffpe-trap https://gcc.gnu.org/onlinedocs/gfortran/Debugging-Options.html
> 
> Is it possible to have a similar functionality in julia? That would be very useful to debug a NaN or Inf suddenly appearing in a program.
> 
> https://github.com/JuliaLang/julia/pull/6170 looks related

I tried the code … :

```julia
julia> setfpexceptions(FE_DIVBYZERO, FE_INVALID, FE_OVERFLOW) do
           1/0.0 # your code here
       end
Inf

```

This did not work, as I thought it would, because it’s evaluated at compile time, but with real code doing such it does.
