Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . Write a C implementation of Kahan s summation algorithm. Your task is to write a function that takes an array of double precision

1. Write a C implementation of Kahans summation algorithm. Your task is to write a function that
takes an array of double precision floating point numbers and returns its sum. The prototype of your
function should be:
1 double kahan_sum(double* a, int length);
For comparison also write a function that implements the naive sum of all the elements of the array in
order (i.e. a[0]+ a[1]+...+ a[length -1]). The prototype of this function should be:
1 double naive_sum(double* a, int length);
Test your functions with the following code:
1 double table[10000];
2 table[0]=1.0;
3 for (int i =1; i <10000; i++){
4 table[i]=1e-16;
5}
6 printf("naive =%1.14e
", naive_sum(table,10000));
7 printf("kahan =%1.14e
", kahan_sum(table,10000));
8 return(0);
9}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Navigating The Supply Chain Maze A Comprehensive Guide To Optimize Operations And Drive Success

Authors: Michael E Kirshteyn Ph D

1st Edition

B0CPQ2RBYC, 979-8870727585

More Books

Students also viewed these Databases questions

Question

How is slaked lime powder prepared ?

Answered: 1 week ago

Question

Why does electric current flow through acid?

Answered: 1 week ago

Question

What is Taxonomy ?

Answered: 1 week ago

Question

1. In taxonomy which are the factors to be studied ?

Answered: 1 week ago