×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

I need 3.6 not 3.5999

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.

RE: I need 3.6 not 3.5999

(OP)
No, it is not. I am working on a code for my research.
I'm just biginner of Fortran.
Thank you.

RE: I need 3.6 not 3.5999

(OP)
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.
 

RE: I need 3.6 not 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: Eng-Tips.com Forum Policies

RE: I need 3.6 not 3.5999

(OP)
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.

RE: I need 3.6 not 3.5999

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: Eng-Tips.com Forum Policies

RE: I need 3.6 not 3.5999

(OP)
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.

RE: I need 3.6 not 3.5999

(OP)
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.

RE: I need 3.6 not 3.5999

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
http://katmarsoftware.com

RE: I need 3.6 not 3.5999

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

RE: I need 3.6 not 3.5999

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

RE: I need 3.6 not 3.5999

==> 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

RE: I need 3.6 not 3.5999

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!

RE: I need 3.6 not 3.5999

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

RE: I need 3.6 not 3.5999

So its not stored as a mantissa and an exponent?

RE: I need 3.6 not 3.5999

(OP)
IRstuff,

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

 

RE: I need 3.6 not 3.5999

see:
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

(OP)
Integer BURB
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

(OP)
I want to get right value for 'BURB'. I understand you about the binary numbers.
I want to use 'Burb' as a indicator of interation. That's it.

RE: I need 3.6 not 3.5999

Welcome to the delights of mixed-mode arithmetic.  It causes tears (and blood, and sweat) in every language I have ever worked in.
 

RE: I need 3.6 not 3.5999

I believe Denial is correct. If you are leaving the REAL to INTEGER conversion up to the compiler then you are asking for trouble, in any language or compiler. Rather do it under your own control. See the post by johnhors in thread545-95464: Rounding REAL numbers.

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

It's simpler than that.  BUR can simply be defined as 18 to start with and avoid both the decimal fraction and the division by 0.2.  Likewise, the constant 140/0.2 should simply be written as 140*5 or just 700.  At that point, one wonders what the exact purpose of the additional 1 is.

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

The number is being rounded down.  Use nint to get the nearest integer.

CODE

BURB=NINT(1.0+(BUR+140.0)/0.2)
If you are getting timing problems (say you need to compute this a few million times, use

CODE

BURB=NINT(1.0+(BUR+140.0)*5.0)

RE: I need 3.6 not 3.5999

IRstuff - I agree with your comments in your last post. I would also question the OP's statement "I am making a code using fortran77." as fortran77 is now obsolete, I use silverfrost ftn95, they no longer support their ftn77 product, in the gnu community f77 is also no longer supported having moved on to g95 or gfortran.

RE: I need 3.6 not 3.5999

Hello:
Just try this for Format F3.1, this should take care of it

Thanks
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

White Paper - How ESI is Helping Move New Medical Device Product to Market Quicker & More Cost Effic
Early Supplier Involvement has long been a strategy employed by manufacturers to produce innovative products. Now, it almost seems like a necessity. Because decisions made in the design phase can positively affect product quality and costs, this can help add value to OEM bottom lines. This white paper will discuss many facets of ESI, including why it’s so valuable today, what challenges limit the benefits of ESI, how cost is impacted, and more. Download Now
White Paper - Moving to a Driverless Future
This white paper describes what we see as the best practices to support a sustainable engineering process for autonomous vehicle design. It exposes how to use simulation and testing in common frameworks to enable design exploration, verification and validation for the development of autonomous cars at a system, software and full-vehicle level to drive a mature product development process for automated driving. Download Now
Research Report - How Engineers are Using Remote Access
Remote access enables engineers to work from anywhere provided they have an internet connection. We surveyed our audience of engineers, designers and product managers to learn how they use remote access within their organizations. We wanted to know which industries have adopted remote access, which software they are using, and what features matter most. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close