Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:49:51+00:00 2026-05-23T09:49:51+00:00

I am doing some floating point calculations and the results are not as accurate

  • 0

I am doing some floating point calculations and the results are not as accurate as I want them to be.

This is the algorithm:

...
center = (max_x + min_x) / 2
distance = old_x - center
new_x = center + (distance * factor)

return new_x

min_x, max_x, and old_x are all floats.
I believe that the greatest error is introduced when I’m taking the average of the max and the min, and then the error is multiplied by the factor (which can be a float).

How can I minimize the error due to FP computation so that new_x is as precise as it can be?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:49:51+00:00Added an answer on May 23, 2026 at 9:49 am

    If old_x and center are close then you’re losing precision.

    It’s called Loss of significance

    You could change the calculation so the subtraction happenS in the end:

    center = (max_x + min_x) / 2
    new_x = (center + (old_x * factor)) - (center * factor)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to represent a floating-point number as a string rounded to some number
Say you're writing a C++ application doing lots of floating point arithmetic. Say this
I'm creating a web application that does some very heavy floating point arithmetic calculations,
I am doing some floating point arithmetic and having precision problems. The resulting value
I tried doing some floating point comparison and here is what I found: 130
I am doing some input/output between a c++ and a python program (only floating
I`m doing some web.config modifications with SPWebConfigModification class. When adding them to WebApplication and
I'm doing some exercises for Computer Science university and one of them is about
I was doing some rounding calculations and happened upon a question. How can I
So in doing some of the Project Euler problems, I want to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.