Infnan
Fortran functions for checking Inf/NaN. They should work even if the compilers are invoked with aggressive optimization flags such as `gfortran -Ofast`.
Install / Use
/learn @equipez/InfnanREADME
infnan
infnan.f90 implements a module that provides some functions for checking Inf/NaN. They aim to work
even when compilers are invoked with aggressive optimization flags, including particularly gfortran -Ofast.
Many ways exist to implement functions like is_nan. However, not all of them work with
aggressive optimization flags. For example, there are such discussions on
StackOverflow and Fotran Discourse.
The ieee_is_nan included in ieee_arithmetic of gfortran 9.3.0 does not work with aggressive
optimization flags like -Ofast.
Given the fact that -Ofast implies -ffinite-math-only, we cannot blame ieee_arithmetic for
the failure. In addition, some compilers
(gfortran 9.3.0, ifort 21.0, and nagfor 7.0) may not behave in the most desirable way concerning
the return kind of ieee_is_nan when some special compilation flags are imposed, as has been discussed
on Fortran Discourse.
My choice of implementation is totally empirical, in the sense that I have not studied in-depth what the aggressive optimization flags really do, but only made some tests and found some implementation that worked correctly. In other words, I do not know why my implementation works but other implementations may not. The story may change when compilers are changed/updated.
The good news is, I have tested the functions using ten compilers with the most
aggressive optimization flags that I can figure out, and they all succeeded. In particular, the functions work well with gfortran -Ofast for gfortran 9.3.0 and 10.3.0,
but those based on ieee_arithmetic fail. Such a test can be done by
cd test && make clean && make gtest
However, we did observe failures. See the issues for details. I will be very happy to hear your suggestions on how to fix them.
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
