FORTRAN 77 input absolute values

1. Sep 9, 2014

tyogav

How to input absolute values in FORTRAN77?

This was the code I used
PRINT *,H

The input I gave was 0.01
But the output I got was 0.00999999978.

2. Sep 9, 2014

Staff: Mentor

The decimal 0.01 can't be written as an exact floating point binary. The result you got is the closest you can get with a real*4. If you need more precision, try real*8.

3. Sep 9, 2014

tyogav

I m writing a FORTRAN program for Simpson's 1/3 rule. In that I m taking three inputs, upper limit and lower limit of the integral and the interval.

For eg: lower limit is 0, upper limit is 1, interval(h) is 0.1. Naturally the no. of intervals(n) is 10. But it shows 9.

This is the code
n=(b-a)/h

It seems that it is because of the fact that n is just the integer part of the answer (which according to FORTRAN is 9.999...etc) Any way to solve it?

I tried nint.. It worked. I m looking for other options

4. Sep 9, 2014

Staff: Mentor

The NINT() function is exactly the way I would get the correct value of N in this situation. I can't think of any other reasonable way to do it.

5. Sep 9, 2014

Staff: Mentor

The other possibility is to have n instead of h as a parameter.