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

  • SEARCH
  • Home
  • 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 6774895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:50:31+00:00 2026-05-26T15:50:31+00:00

I was looking for satisfactory and safe workaround to my double precision issue specified

  • 0

I was looking for satisfactory and safe workaround to my double precision issue specified to this problem:

enter image description here

This program tries to find how many small circle can fit into a large circle. It fills the large circle and then culls those that intersect the large circumference. using this formula:

distance_small_pos_from_center + small_radius < big_radius

All calculations were in double, except for screen output on WinForms which takes int for coords.

enter image description here

The above image shows the result of the culling. You can see that it is not symmetric when it should really be because the constraint is that there must be one small circle exactly in the center. I step through the code and find that this is because some calculations yield, for example,

99.9999999 < 100

This answer C++ double precision and rounding off says we should use all the precision available, but in this case, I had to do a Math.Round(distance_small_pos_from_center + small_radius, 3) using 3 arbitarily.

The result of the culling differs very much without Math.Round. In retrospect, this is one kind of bug that is hard to detect if I had not drawn it out. Maybe I did something wrong, or didn’t understand doubles as much as I thought I had.

So, anyone has solutions or tips to avoid this kind of problem?

  • 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-26T15:50:32+00:00Added an answer on May 26, 2026 at 3:50 pm

    Sorry for not beeing able to provide a complete answer to your question, but i have no time for that right now. But when you compare floats, compare them with a “tolerance” since a float is not exact.

    EDIT: modified with abs() in case you don’t know which is big and small, as pointed out by Hans Kesting

    Ie, do something like if(abs(big_radius - distance_small_pos_from_center) < epsilon) where epsilon is your tolerance, selected with consideration to how “inexact” the floats will be in the range where you are working..

    For more precise information see:

    http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

    http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html

    http://www.cplusplus.com/forum/articles/3638/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't been able to find any satisfactory coverage of this topic all in
I am looking for satisfactory options for unit testing my .NET DAL classes; since
Looking to do a very small, quick 'n dirty side project. I like the
Looking at n3092, in §6.5.4 we find the equivalency for a range-based for loop.
Looking for a function like this in ColdFusion, allowing me to show dates as
I have honestly looked for over an hour for a satisfactory answer to this
I have been looking all over for an answer to this question, but can't
I have been thinking about this problem for long enough but cannot come up
Sorry if this appears repetitive but I've been all over the interwebz looking for
This issue only exists under IIS5.1. I have found a way of resolving the

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.