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 164715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:47:36+00:00 2026-05-11T11:47:36+00:00

After one hour of trying to find a bug in my code I’ve finally

  • 0

After one hour of trying to find a bug in my code I’ve finally found the reason. I was trying to add a very small float to 1f, but nothing was happening. While trying to figure out why I found that adding that small float to 0f worked perfectly.

Why is this happening? Does this have to do with ‘orders of magnitude’? Is there any workaround to this problem?

Thanks in advance.

Edit:

Changing to double precision or decimal is not an option at the moment.

  • 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. 2026-05-11T11:47:36+00:00Added an answer on May 11, 2026 at 11:47 am

    Because precision for a single-precision (32 bit) floating-point value is around 7 digits after the decimal point. Which means the value you are adding is essentially zero, at least when added to 1. The value itself, however, can effortlessly stored in a float since the exponent is small in that case. But to successfully add it to 1 you have to use the exponent of the larger number … and then the digits after the zeroes disappear in rounding.

    You can use double if you need more precision. Performance-wise this shouldn’t make a difference on today’s hardware and memory is often also not as constrained that you have to think about every single variable.

    EDIT: As you stated that using double is not an option you could use Kahan summation, as akuhn pointed out in a comment.

    Another option may be to perform intermediary calculations in double-precision and afterwards cast to float again. This will only help, however, when there are a few more operations than just adding a very small number to a larger one.

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

Sidebar

Related Questions

I am very fresh to asp.net mvc and jQuery. After one day trying, I
after one hour googling, I can't find the right answer to the issue I'm
In docs link about expires # Task expires after one minute from now. add.apply_async(args=[10,
I'm trying to get java to perform one action after one click and then
I've tried in 1 hour now, trying to find out how I could extract
I have to read the tomcat log file,and after some time(for example:one hour) I
After one week searching and converting many algorithm from other language into php to
I use Request.Queue from more to fire my request one after one when the
I am facing a problem while disabling the command button after one click. I
Any idea why after replacing one UIView with another (with the same Touch event

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.