Permalink
Browse files

Added ldexp() function. pow() now also accepts negative numbers.

  • Loading branch information...
SamuelSarle committed Oct 4, 2017
1 parent 5f15c61 commit e99b64e4e2f46d6501a2a080093cc8719d7b7647
Showing with 28 additions and 3 deletions.
  1. +18 −0 src/math/ldexp.c
  2. +10 −3 src/math/pow.c
View
@@ -0,0 +1,18 @@
/* This is free and unencumbered software released into the public domain. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/**
* @date 2017-10-04
* @author Samuel Sarle
* @see http://libc11.org/math/ldexp.html
*/
#include <math.h> //For pow()
double
ldexp(const double x, const long long y) {
return x * pow(2, y);
}
View
@@ -13,9 +13,16 @@
double
pow(const double x, const double y) {
double z = 1;
for (unsigned long long i = 0; i < y; i++) {
z *= x;
if (y > 0) {
for (unsigned long long i = 0; i < y; i++) {
z *= x;
}
}
if (y < 0 && x != 0) {
for (long long i = 0; i > y; i--) {
z /= x;
}
}
return z;
}
}

0 comments on commit e99b64e

Please sign in to comment.