Floating Sum Stability

Floating Sum Stability

Hard Computer Mathematics Numerical Precision 37 views
Explanation Complexity

Problem Statement

Given n decimals, sum them and print with 6 decimals (show stable summation idea).

Input Format

n then n decimals.

Output Format

One number.

Example

3
0.1 0.2 0.3
0.600000

Constraints

n

Input / Output Format

Input Format
n then n decimals.
Output Format
One number.
Constraints
n

Examples

Input:
3 0.1 0.2 0.3
Output:
0.600000

Example Solution (Public)

Computer Mathematics
Use Kahan summation: keep compensation c. For each x: y=x-c; t=sum+y; c=(t-sum)-y; sum=t.

Official Solution Code

Use Kahan summation: keep compensation c. For each x: y=x-c; t=sum+y; c=(t-sum)-y; sum=t.
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.