FORTRAN 77 input absolute values

In summary, the conversation discusses how to input absolute values in FORTRAN77 and how to use the NINT() function to get the correct value of n in a Simpson's 1/3 rule program. The use of real*8 is suggested for more precision in calculations.
  • #1
tyogav
14
0
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.
 
Technology news on Phys.org
  • #2
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
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:
 
  • #4
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
The other possibility is to have n instead of h as a parameter.
 

Related to FORTRAN 77 input absolute values

1. How do I input absolute values in FORTRAN 77?

To input absolute values in FORTRAN 77, you can use the ABS function. This function takes in a numeric value and returns its absolute value. For example, ABS(-5) will return 5.

2. Can I input absolute values for multiple numbers at once in FORTRAN 77?

Yes, you can input absolute values for multiple numbers at once in FORTRAN 77. You can use the ABS function in a DO loop to iterate through a list of numbers and return their absolute values.

3. How do I handle negative numbers when inputting absolute values in FORTRAN 77?

In FORTRAN 77, negative numbers are automatically converted to positive numbers when using the ABS function. Therefore, you do not need to handle negative numbers separately when inputting absolute values.

4. Can I use the ABS function to input absolute values for non-numeric data types in FORTRAN 77?

No, the ABS function can only be used for numeric values in FORTRAN 77. If you need to input absolute values for non-numeric data types, you will need to use a different method such as conditional statements.

5. Are there any other functions besides ABS that can be used to input absolute values in FORTRAN 77?

Yes, there are other functions that can be used to input absolute values in FORTRAN 77 such as SIGN and IABS. However, the ABS function is the most commonly used for this purpose.

Similar threads

  • Programming and Computer Science
Replies
25
Views
462
  • Programming and Computer Science
2
Replies
62
Views
4K
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
2
Views
924
  • Programming and Computer Science
Replies
20
Views
3K
  • Programming and Computer Science
Replies
4
Views
651
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
12
Views
978
Back
Top