Just as a complement to existing answers, I want to add an example of how commercial rounds can be implemented without using NINT
L = INT(F + 0.5)
where L is INTEGER and F is a positive REAL number. I found this in the FORTRAN 77 code samples from the last century.
Extending this to negative REAL numbers
L = SIGN(1.0,F)*INT(ABS(F) + 0.5)
and returning to the 80s of the last century, an example of a minimal code is as follows
PROGRAM ROUNDTEST DO 12345 I=0,30 F = -1.0 + I * 0.1 J = INT(F) K = NINT(F) L = SIGN(1.0,F)*INT(ABS(F) + 0.5) PRINT *, I, F, J, K, L 12345 CONTINUE END
which creates a conclusion
$ ./ROUNDTEST 0 -1.00000000 -1 -1 -1 1 -0.899999976 0 -1 -1 2 -0.800000012 0 -1 -1 3 -0.699999988 0 -1 -1 4 -0.600000024 0 -1 -1 5 -0.500000000 0 -1 -1 6 -0.399999976 0 0 0 7 -0.300000012 0 0 0 8 -0.199999988 0 0 0 9 -9.99999642E-02 0 0 0 10 0.00000000 0 0 0 11 0.100000024 0 0 0 12 0.200000048 0 0 0 13 0.300000072 0 0 0 14 0.399999976 0 0 0 15 0.500000000 0 1 1 16 0.600000024 0 1 1 17 0.700000048 0 1 1 18 0.800000072 0 1 1 19 0.899999976 0 1 1 20 1.00000000 1 1 1 21 1.10000014 1 1 1 22 1.20000005 1 1 1 23 1.29999995 1 1 1 24 1.40000010 1 1 1 25 1.50000000 1 2 2 26 1.60000014 1 2 2 27 1.70000005 1 2 2 28 1.79999995 1 2 2 29 1.90000010 1 2 2 30 2.00000000 2 2 2
ROUNDTEST compiled and linked by gfortran version 7.4.0
$ gfortran.exe ROUNDTEST.FOR -o ROUNDTEST
Hope this helps you if you have to deal with the old FORTRAN code.
source share