# Return NaN instead of DomainError

**URL:** <https://discourse.julialang.org/t/return-nan-instead-of-domainerror/15493>\
**Category:** General Usage\
**Created:** [September 25, 2018, 10:25pm UTC](https://discourse.julialang.org/t/return-nan-instead-of-domainerror/15493 "2018-09-25T22:25:02Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [July 26, 2019, 2:10pm UTC](https://discourse.julialang.org/t/return-nan-instead-of-domainerror/15493/21 "2019-07-26T14:10:05Z")

</div>

Basically as I said above, “if a 3rd-party library calls C (or other) function or external program” - so you have a C library Foo, a Julia wrapper Foo.jl which just ccall’s the C code and performs some postprocessing calculations. If you as the package user want to evaluate function from Foo.jl in a region they are not defined, all you get is an exception instead of e.g. an array where only the out-of-bounds values are NaN’s.

This is an actual case I have in Python now, and there it obviously works fine - all NaNs propagate straight to the final result. Was looking for simplest ways to port and the library to julia.

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [July 26, 2019, 2:19pm UTC](https://discourse.julialang.org/t/return-nan-instead-of-domainerror/15493/22 "2019-07-26T14:19:39Z")

</div>

Another issue with using this approach is that it’s significantly slower - `NaNMath` is about 2x slower for me compared to `Base` math functions.

[Previous page](https://discourse.julialang.org/t/return-nan-instead-of-domainerror/15493.md?page=1)
