Fortran FORTRAN 77 input absolute values

AI Thread Summary
In FORTRAN 77, inputting absolute values can lead to precision issues, as floating-point numbers like 0.01 cannot be represented exactly in binary, resulting in outputs like 0.00999999978. To achieve greater precision, using real*8 instead of real*4 is recommended. When calculating the number of intervals for Simpson's 1/3 rule, the integer division can yield unexpected results, such as showing 9 instead of 10 due to truncation. The NINT() function effectively resolves this issue by rounding to the nearest integer. Alternative solutions may involve adjusting parameters, but NINT() is the most straightforward approach.
tyogav
Messages
14
Reaction score
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
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.
 
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:
 
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.
 
The other possibility is to have n instead of h as a parameter.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
25
Views
3K
Replies
20
Views
4K
Replies
2
Views
1K
Replies
29
Views
3K
Replies
12
Views
2K
Replies
3
Views
2K
Replies
2
Views
1K
Back
Top