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 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

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