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

see:
[red]Step 3
Attachment
[/red] 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
 
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.
 
You should already have the educational background to understand this, so I will ask again, what is this assignment for?

TTFN

FAQ731-376
 
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.
 
As an engineer, you've already gotten everything you need to solve your problem in the postings above.

TTFN

FAQ731-376
 
Welcome to the delights of mixed-mode arithmetic. It causes tears (and blood, and sweat) in every language I have ever worked in.
 
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.

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
 
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
 
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)
 
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.
 
Hello:
Just try this for Format F3.1, this should take care of it

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor