# min(NaN,5) = NaN (why no @fastmath?)

**URL:** <https://discourse.julialang.org/t/min-nan-5-nan-why-no-fastmath/93736>\
**Category:** General Usage\
**Tags:** nan\
**Created:** [January 29, 2023, 5:07pm UTC](https://discourse.julialang.org/t/min-nan-5-nan-why-no-fastmath/93736 "2023-01-29T17:07:14Z")\
**Posts on this page:** 1\
**Showing post:** 40

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [February 1, 2023, 11:26pm UTC](https://discourse.julialang.org/t/min-nan-5-nan-why-no-fastmath/93736/40 "2023-02-01T23:26:57Z")

</div>

This is what I get:

```julia
julia> @btime findmax_nan($x)
  1.179 ms (0 allocations: 0 bytes)
(3.0f0, 1)

julia> @btime argmax(first, Iterators.filter(!isnan∘first, zip($x, keys($x))))
  3.121 ms (0 allocations: 0 bytes)
(3.0f0, 1)

julia> @btime findmax(skip(isnan, $x))
  3.156 ms (0 allocations: 0 bytes)
(3.0f0, 1)

```

> **Julia 1.9.0-beta3**
>
> ```julia
> julia> versioninfo()
> Julia Version 1.9.0-beta3
> Commit 24204a7344 (2023-01-18 07:20 UTC)
> Platform Info:
> OS: Windows (x86_64-w64-mingw32)
> CPU: 20 × 12th Gen Intel(R) Core(TM) i9-12900HK
> WORD_SIZE: 64
> LIBM: libopenlibm
> LLVM: libLLVM-14.0.6 (ORCJIT, alderlake)
> Threads: 20 on 20 virtual cores
> 
> ```

~~I suspect [this](https://discourse.julialang.org/t/range-statistics/92518/24).~~

Edit: This seems to be a case where the structure of the problem allows for `findmax_nan` to be a more optimal solution than using `Iterators.filter` or `skip`. For example, if `x` has less `NaN` values, then `findmax(skip(isnan, x))` runs faster, and in the case where there are no `NaN`s, it runs nearly as fast (1.45ms here).

Personally I’d rather drop `findmax(skip(isnan, x))` into my code than write my own `findmax_nan` function, unless it was a very hot loop that justified such an optimization, considering that the former pattern is less error-prone and more generally applicable. But the context of the OP (about fastmath) makes this off-topic.

---

_[View the full topic](https://discourse.julialang.org/t/min-nan-5-nan-why-no-fastmath/93736)._
