×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-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

*Tek-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

Jobs

accuracy in gfortran

accuracy in gfortran

accuracy in gfortran

(OP)
if all the variables at first are integer isn't integer multiplication supposed to be exact ?
Even though i am getting very large numbers(as long as not overflow): anyway at the end i will have to divide a floating point number by the integer(s). There are several steps and at first i just divided the floating point number by the integers at each step and was getting more off than what i should have thought reasonable so then i changed strategy and multiplied all the integers and at the end divided by the product.Assuming integer multiplication is exact would not the 2nd way of doing all the integer multiplications first and then divide the floating point number by the final(rather large but not enough to overflow or underflow) result be more accurate than doing several divisions of the floating point number by the integers at each step.
The difference in these two ways was a lot more than i would have thought - like around 15% or so.
The floating point was single precision and the number of integer products was less than 20 i think. The reason i would have thought the 2nd way is better is because only have one floating point division by an integer(all be it much larger) instead of several.

RE: accuracy in gfortran

It does depend on what the actual mathematical calculation is. Integer division can change the result dramatically

Take some simple addition

(28 / 10) + (29 /10)
= 2 + 2
= 4

but

(28 + 29) / 10
= 57 / 10
= 5

With multiplication

(24 / 10) * (3 / 2)
= 2 * 1
= 2

But

(24 * 3)/(10 * 2)
= 72 / 20
= 3

RE: accuracy in gfortran

(OP)
You are dividing integer by integer. I don't have that case at all. I am only multiplying integer times integer and at the end dividing floating point by the integers product which i presume should be more accurate or perhaps at worst same? than dividing the float by each integer at a time rather than waiting till the end and dividing only once by the integers product.

RE: accuracy in gfortran

Are you dividing by float or double precision? Floats only have 6 digit accuracy. Also - it is just significant figures: not decimal places. The closer you are to 1, the more accurate the answer.

Dividing may produce a different result to multiplying by the reciprocal. Mathematically, it is the same. Work out on a calculator or by hand what the answer should be and check the two methods.

RE: accuracy in gfortran

(OP)
I was dividing floats by integers. Yea I know am going to get round off,floating point error no matter what. I was just asking if generally one way was better than the other. That is dividing floats as the program goes by one or smaller number of integers as i go or wait till at the end and then then divide the final float number by the product of all the integers in one final step.

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 Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

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

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

Close Box

Join Tek-Tips® Today!

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

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close