Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need 3.6 not 3.5999

Status
Not open for further replies.

Willsong

Mechanical
Jul 7, 2009
13
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.
 
Replies continue below

Recommended for you

No, it is not. I am working on a code for my research.
I'm just biginner of Fortran.
Thank you.
 
So, do you need numerically correct, or cosmetically correct?

TTFN

FAQ731-376
 
I need to use the value to calculate another value. I defined the value of 3.6 to "CA". The problem is that "CA" is called as 3.59999. It gave me wrong answer because the calculation is conducted with 3.5999.
 
I think you have a more serious problem of why you can get a "right" answer at 3.59999, but a "wrong" answer at 3.5999. The uncertainty in any real world scenario will swamp out this trivial precision error.

You need to explain more about your problem.

TTFN

FAQ731-376
 
Sorry about bothering you. I mean I want to use 3.6. But, during the computation, 3.5999 is used instead of 3.6 even though I input 3.6 as an value.
 
The issue is that you cannot get exactly 3.6, because it's not a binary number. Have you checked the numerical precision of your variables? Do you really expect people to know what you did in your program without a listing?

TTFN

FAQ731-376
 
I appreciate your explanation.
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.
 
Have you read the manual? What did the prof say?

TTFN

FAQ731-376
 
Yes, I'm reading the manual. It is quite difficult to me. It is my first coding in my life.
I'm learning and, at the same time, coding the program.
 
It is a long time since I worked in FORTRAN - it was still called FORTRAN IV when I learnt it! Did you declare the TYPE for your variable CA? Try declaring it as DOUBLE PRECISION or whatever the equivalent is in FORTRAN 77. If you have enough 9's after the 5 the value becomes indistinguishable from 3.6

Katmar Software
Engineering & Risk Analysis Software
 
Another trick is to multiply by 36 and then divide the answer by 10.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Sorry Cajun, but that is nonsense!

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
 
==> Sorry Cajun, but that is nonsense!
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
 
Cajun,

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!
 
Believe what you will, but I know the actual code being generated by many, not all, but many FORTRAN compilers.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
You still haven't posted a listing.

TTFN

FAQ731-376
 
IRstuff,

The code is quite long. How can I post it?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor