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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:22:58+00:00 2026-05-14T00:22:58+00:00

Say you have 100000000 32-bit floating point values in an array, and each of

  • 0

Say you have 100000000 32-bit floating point values in an array, and each of these floats has a value between 0.0 and 1.0. If you tried to sum them all up like this

result = 0.0;
for (i = 0; i < 100000000; i++) {
    result += array[i];
}

you’d run into problems as result gets much larger than 1.0.

So what are some of the ways to more accurately perform the summation?

  • 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-14T00:22:58+00:00Added an answer on May 14, 2026 at 12:22 am

    Sounds like you want to use Kahan Summation.

    According to Wikipedia,

    The Kahan summation algorithm (also known as compensated summation) significantly reduces the numerical error in the total obtained by adding a sequence of finite precision floating point numbers, compared to the obvious approach. This is done by keeping a separate running compensation (a variable to accumulate small errors).

    In pseudocode, the algorithm is:

    function kahanSum(input)
     var sum = input[1]
     var c = 0.0          //A running compensation for lost low-order bits.
     for i = 2 to input.length
      y = input[i] - c    //So far, so good: c is zero.
      t = sum + y         //Alas, sum is big, y small, so low-order digits of y are lost.
      c = (t - sum) - y   //(t - sum) recovers the high-order part of y; subtracting y recovers -(low part of y)
      sum = t             //Algebraically, c should always be zero. Beware eagerly optimising compilers!
     next i               //Next time around, the lost low part will be added to y in a fresh attempt.
    return sum
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a TextBox with the value 1000000 . How can I
I have run into an interesting problem lately: Lets say I have an array
Inspired by Raymond Chen's post , say you have a 4x4 two dimensional array,
Say I have a picture 1000x1000. Is there any way to set a background
Lets say have this immutable record type: public class Record { public Record(int x,
Say I have a couple of basic objects like so: [Serializable] public class Base
say i have a nvarchar field in my database that looks like this 1,
Say I have a class definition: class CustomClass { int member; }; Why is
Say I have real, dimension(0:100) :: realResults and I want to iterate over realResults
Say I have the following: namespace SomeProject { public interface ISomething { string SomeMethod();

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.