Giter Club home page Giter Club logo

infnan's Introduction

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.

infnan's People

Contributors

dependabot[bot] avatar zaikunzhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

wcdawn

infnan's Issues

`is_nan` does not work with `ifx -fast`

is_nan does not work with ifx -fast, the version of ifx being ifx (IFORT) 2022.1.0 20220316. The system is Ubuntu 20.04.

Here is the error information.

cd test && ifx -fast -o xtest ../consts.f90 ../infnan.f90 ieee_infnan.f90 testinfnan.f90 test.f90 && ./xtest

Single-precision tests:
 IS_NAN:  F F F F F F F F F F F F F F F F F F F
 IEEE_IS_NAN:  F F T T F F F F F F F F F F F F F F F
Some tests failed. The data is
Infinity    -Inf     NaN     NaN  1.E+00 -1.E+00  1.E-38 -1.E-38  0.E+00  0.E+00  3.E+38 -3.E+38  1.E-07 -1.E-07  1.E-38 -1.E-38  0.E+00  1.E+00 -1.E+00

Double-precision tests:
 IS_NAN:  F F F F F F F F F F F F F F F F F F F
 IEEE_IS_NAN:  F F T T F F F F F F F F F F F F F F F
Some tests failed. The data is
Infinity    -Inf     NaN     NaN  1.D+00 -1.D+00  2.-308 -2.-308  0.D+00  0.D+00  2.+308 -2.+308  2.D-16 -2.D-16  2.-308 -2.-308  0.D+00  1.D+00 -1.D+00
 
1

Note that ieee_is_nan works in this case.

`is_nan` does not work with `flang -Ofast` of `flang -ffast-math`

$ uname -a
Linux  5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

$ flang --version
flang version 15.0.3
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/zaikunzhang/local/flang/bin

$flang -O3 -Ofast -ffast-math   -o ftest ../consts.f90 ../infnan.f90 ieee_infnan.f90 testinfnan.f90 test.f90
$./ftest

Single-precision tests:
 IS_NAN:   F  F  F  F  F  F  F  F  F  F  F  F  F  F  F  F  F  F  F
 IEEE_IS_NAN:   F  F  T  T  F  F  F  F  F  F  F  F  F  F  F  F  F  F  F
Some tests failed. The data is
     Inf    -Inf     NaN     NaN  1.E+00 -1.E+00  0.E+00 -0.E+00  0.E+00 -0.E+00  3.E+38 -3.E+38  1.E-07 -1.E-07  1.E-38 -1.E-38  0.E+00  1.E+00 -1.E+00

Double-precision tests:
 IS_NAN:   F  F  F  F  F  F  F  F  F  F  F  F  F  F  F  F  F  F  F
 IEEE_IS_NAN:   F  F  T  T  F  F  F  F  F  F  F  F  F  F  F  F  F  F  F
Some tests failed. The data is
     Inf    -Inf     NaN     NaN  1.D+00 -1.D+00  0.D+00 -0.D+00  0.D+00 -0.D+00  2.+308 -2.+308  2.D-16 -2.D-16  2.-308 -2.-308  0.D+00  1.D+00 -1.D+00
 
Warning: ieee_invalid is signaling
Warning: ieee_inexact is signaling

add topics

I suggest adding the topics floating-point, fortran, numerical in the About section.

`is_nan` does not work with `gfortran-8 -O3 -ffast-math -Ofast -flto` on Kunpeng Platform with Ubuntu 18.04 Linux 4.15.0-166-generic

On Kunpeng Platform with Ubuntu 18.04 Linux 4.15.0-166-generic, is_nan fails to identify NaN when compiled with gfortran-8 -O3 -ffast-math -Ofast -flto (ieee_is_nan does not work either).

The details are as follows.

$ lscpu
Architecture:        aarch64
Byte Order:          Little Endian
CPU(s):              2
On-line CPU(s) list: 0,1
Thread(s) per core:  1
Core(s) per socket:  2
Socket(s):           1
NUMA node(s):        1
Vendor ID:           0x48
Model:               0
Stepping:            0x1
BogoMIPS:            200.00
L1d cache:           64K
L1i cache:           64K
L2 cache:            512K
L3 cache:            32768K
NUMA node0 CPU(s):   0,1
Flags:               fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma dcpop asimddp asimdfhm

$ uname -a 
Linux kunpeng-0001 4.15.0-166-generic #174-Ubuntu SMP Wed Dec 8 19:08:37 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux

$ gfortran --version
GNU Fortran (Ubuntu/Linaro 8.4.0-1ubuntu1~18.04) 8.4.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cd test && make clean && make gtest
rm -f *.o *.mod *.dbg *test
gfortran -O3 -ffast-math -Ofast -flto -o gtest ../consts.f90 ../infnan.f90 ieee_infnan.f90 testinfnan.f90 test.f90
./gtest

Single-precision tests:
 IS_NAN:  F F F F F F F F F F F F F F F F F F F
 IEEE_IS_NAN:  F F F F F F F F F F F F F F F F F F F
Some tests failed. The data is
Infinity    -Inf     NaN     NaN  4.E+01 -4.E+01  0.E+00 -0.E+00  0.E+00 -0.E+00  3.E+38 -3.E+38  1.E-07 -1.E-07  1.E-38 -1.E-38  0.E+00  1.E+00 -1.E+00

Double-precision tests:
 IS_NAN:  F F F F F F F F F F F F F F F F F F F
 IEEE_IS_NAN:  F F F F F F F F F F F F F F F F F F F
Some tests failed. The data is
Infinity    -Inf     NaN     NaN  4.D+01 -4.D+01  1.D+00 -1.D+00  0.D+00 -0.D+00  2.+308 -2.+308  2.D-16 -2.D-16  2.-308 -2.-308  0.D+00  1.D+00 -1.D+00
 
Note: The following floating-point exceptions are signalling: IEEE_INVALID_FLAG IEEE_OVERFLOW_FLAG
STOP 1
Makefile:65: recipe for target 'gtest' failed
make: *** [gtest] Error 1

add topic nan

I suggest adding the topic nan in the About section.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.