I need 3.6 not 3.5999
I need 3.6 not 3.5999
(OP)
Hi all,
I am making a code using fortran77.
I input 3.6. Strangely when I call the value, it gives me 3.5999.
Do you know how to fix this problem?
Please help me.
Thank you.
I am making a code using fortran77.
I input 3.6. Strangely when I call the value, it gives me 3.5999.
Do you know how to fix this problem?
Please help me.
Thank you.





RE: I need 3.6 not 3.5999
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: I need 3.6 not 3.5999
I'm just biginner of Fortran.
Thank you.
RE: I need 3.6 not 3.5999
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: I need 3.6 not 3.5999
RE: I need 3.6 not 3.5999
You need to explain more about your problem.
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: I need 3.6 not 3.5999
RE: I need 3.6 not 3.5999
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: I need 3.6 not 3.5999
I understand what you mean.
Frankly, I don't know how to check the numerical precision.
Could you let me know how to check?
Thank you.
RE: I need 3.6 not 3.5999
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: I need 3.6 not 3.5999
I'm learning and, at the same time, coding the program.
RE: I need 3.6 not 3.5999
Katmar Software
Engineering & Risk Analysis Software
http://katmarsoftware.com
RE: I need 3.6 not 3.5999
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: I need 3.6 not 3.5999
If you work with integer variables and divide 360 by 10, yes you would get 36, no problem.
But divide 36 by 10, with integer variables would give 3, with real variables (whether single or double precision) you would get something like 3.599999 or 3.600001, but never precisiely 3.6
RE: I need 3.6 not 3.5999
Not, it is a quite valid technique to substantially reduce floating point roundoff error.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: I need 3.6 not 3.5999
Real variables in fortran are stored as a mantissa and an exponent.
A single precision real variable is 4 bytes = 32 bits, of those 32 bits, 24 store the mantissa and 8 store the exponent.
Thus changing the value of the exponent will not change the accuracy of computation in fortran!
In fact by including the additional computation of dividing by 10 you are introducing more round off errors not reducing them!
RE: I need 3.6 not 3.5999
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: I need 3.6 not 3.5999
RE: I need 3.6 not 3.5999
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: I need 3.6 not 3.5999
The code is quite long. How can I post it?
RE: I need 3.6 not 3.5999
Step 3
Attachment at bottom of the dialog box.
You need to figure out what to extract. How do you expect anyone to debug your code, sight unseen?
Why is your manager giving you such a complicated task?
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: I need 3.6 not 3.5999
DOUBLE PRECISION BUR
BUR=3.6
BURB=1.0+(BUR+140.0)/0.2
In this code, 'BURB' is calculated as 718.
I want 719.
RE: I need 3.6 not 3.5999
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: I need 3.6 not 3.5999
I want to use 'Burb' as a indicator of interation. That's it.
RE: I need 3.6 not 3.5999
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: I need 3.6 not 3.5999
RE: I need 3.6 not 3.5999
Do something like
Integer BURB
DOUBLE PRECISION BUR, BURA
BUR=3.6
BURA=1.0+(BUR+140.0)/0.2
BURB=INT(BURA+0.5)
Katmar Software
Engineering & Risk Analysis Software
http://katmarsoftware.com
RE: I need 3.6 not 3.5999
Just an iota of research would have made it plainly obvious that the coding is at fault. However, you need to review what the purpose of the equation as written is, since it's both cumbersome and questionable in intent.
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: I need 3.6 not 3.5999
CODE
CODE
RE: I need 3.6 not 3.5999
RE: I need 3.6 not 3.5999
Just try this for Format F3.1, this should take care of it
Thanks