This commit is contained in:
zhangyazhou
2022-12-11 21:34:46 +08:00
commit 8a5b8b3292
106 changed files with 2511 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
add_library(MathFunctions mysqrt.cxx)
# TODO 1: State that anybody linking to MathFunctions needs to include the
# current source directory, while MathFunctions itself doesn't.
# Hint: Use target_include_directories with the INTERFACE keyword

View File

@@ -0,0 +1 @@
double mysqrt(double x);

View File

@@ -0,0 +1,24 @@
#include <iostream>
#include "MathFunctions.h"
// a hack square root calculation using simple operations
double mysqrt(double x)
{
if (x <= 0) {
return 0;
}
double result = x;
// do ten iterations
for (int i = 0; i < 10; ++i) {
if (result <= 0) {
result = 0.1;
}
double delta = x - (result * result);
result = result + 0.5 * delta / result;
std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
}
return result;
}