Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

FORTRAN 77 input absolute values

  1. Sep 9, 2014 #1
    How to input absolute values in FORTRAN77?

    This was the code I used
    READ *,H
    PRINT *,H

    The input I gave was 0.01
    But the output I got was 0.00999999978.
     
  2. jcsd
  3. Sep 9, 2014 #2

    DrClaude

    User Avatar

    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.
     
  4. Sep 9, 2014 #3
    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
    Read *,a,b,h
    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 :confused:
     
  5. Sep 9, 2014 #4

    jtbell

    User Avatar

    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.
     
  6. Sep 9, 2014 #5

    DrClaude

    User Avatar

    Staff: Mentor

    The other possibility is to have n instead of h as a parameter.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: FORTRAN 77 input absolute values
  1. Fortran 77 (Replies: 1)

Loading...