diff --git a/src/math/exp.c b/src/math/exp.c new file mode 100644 index 0000000..71830b2 --- /dev/null +++ b/src/math/exp.c @@ -0,0 +1,19 @@ +/* This is free and unencumbered software released into the public domain. */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/** + * @date 2017-10-09 + * @author Samuel Sarle + * @see http://libc11.org/math/exp.html + */ + +double +exp(double x) { + x = 1 + (x / 1048576); + for (int i = 0; i < 20; i++) { + x *= x; + } +} diff --git a/src/math/fabs.c b/src/math/fabs.c index 7c8ba36..e6ee22a 100644 --- a/src/math/fabs.c +++ b/src/math/fabs.c @@ -12,5 +12,5 @@ double fabs(const double x) { - return (x < 0) ? -x: x; + return (x < 0) ? -x : x; } diff --git a/src/math/ldexp.c b/src/math/ldexp.c index e79c300..1d79fdb 100644 --- a/src/math/ldexp.c +++ b/src/math/ldexp.c @@ -4,13 +4,14 @@ #include #endif +#include //For pow() + /** * @date 2017-10-04 * @author Samuel Sarle * @see http://libc11.org/math/ldexp.html */ -#include //For pow() double ldexp(const double x, const long long y) { diff --git a/src/math/sqrt.c b/src/math/sqrt.c new file mode 100644 index 0000000..1929e93 --- /dev/null +++ b/src/math/sqrt.c @@ -0,0 +1,28 @@ +/* This is free and unencumbered software released into the public domain. */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/** + * @date 2017-10-05 + * @author Samuel Sarle + * @see http://libc11.org/math/sqrt.html + */ + +double +sqrt(const double x) { + if (x <= 0) { + return 0; + } + + int i = 0; + while( (i * i) <= x ) { + i++; + } + i--; + double z = x - i * i; //Bakhshali approximation + double y = z / (2 * i); + double w = i + y; + return w - (y * y) / (2 * w); +}