diff --git a/.gitattributes b/.gitattributes index d67c4413..313d53d9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,3 +3,4 @@ *.ini text eol=lf *.h text eol=lf *.cpp text eol=lf +*.c text eol=lf diff --git a/code/espurna/fs_math.c b/code/espurna/fs_math.c index 868ba382..5bf67930 100644 --- a/code/espurna/fs_math.c +++ b/code/espurna/fs_math.c @@ -1,636 +1,636 @@ -/** - * This code is available at - * http://www.mindspring.com/~pfilandr/C/fs_math/ - * and it is believed to be public domain. - */ - -/* BEGIN fs_math.c */ - -#include "libs/fs_math.h" - -#include -/* -** pi == (atan(1.0 / 3) + atan(1.0 / 2)) * 4 -*/ -static double fs_pi(void); -static long double fs_pil(void); - -double fs_sqrt(double x) -{ - int n; - double a, b; - - if (x > 0 && DBL_MAX >= x) { - for (n = 0; x > 2; x /= 4) { - ++n; - } - while (0.5 > x) { - --n; - x *= 4; - } - a = x; - b = (1 + x) / 2; - do { - x = b; - b = (a / x + x) / 2; - } while (x > b); - while (n > 0) { - x *= 2; - --n; - } - while (0 > n) { - x /= 2; - ++n; - } - } else { - if (x != 0) { - x = DBL_MAX; - } - } - return x; -} - -double fs_log(double x) -{ - int n; - double a, b, c, epsilon; - static double A, B, C; - static int initialized; - - if (x > 0 && DBL_MAX >= x) { - if (!initialized) { - initialized = 1; - A = fs_sqrt(2); - B = A / 2; - C = fs_log(A); - } - for (n = 0; x > A; x /= 2) { - ++n; - } - while (B > x) { - --n; - x *= 2; - } - a = (x - 1) / (x + 1); - x = C * n + a; - c = a * a; - n = 1; - epsilon = DBL_EPSILON * x; - if (0 > a) { - if (epsilon > 0) { - epsilon = -epsilon; - } - do { - n += 2; - a *= c; - b = a / n; - x += b; - } while (epsilon > b); - } else { - if (0 > epsilon) { - epsilon = -epsilon; - } - do { - n += 2; - a *= c; - b = a / n; - x += b; - } while (b > epsilon); - } - x *= 2; - } else { - x = -DBL_MAX; - } - return x; -} - -double fs_log10(double x) -{ - static double log_10; - static int initialized; - - if (!initialized) { - initialized = 1; - log_10 = fs_log(10); - } - return x > 0 && DBL_MAX >= x ? fs_log(x) / log_10 : fs_log(x); -} - -double fs_exp(double x) -{ - unsigned n, square; - double b, e; - static double x_max, x_min, epsilon; - static int initialized; - - if (!initialized) { - initialized = 1; - x_max = fs_log(DBL_MAX); - x_min = fs_log(DBL_MIN); - epsilon = DBL_EPSILON / 4; - } - if (x_max >= x && x >= x_min) { - for (square = 0; x > 1; x /= 2) { - ++square; - } - while (-1 > x) { - ++square; - x /= 2; - } - e = b = n = 1; - do { - b /= n++; - b *= x; - e += b; - b /= n++; - b *= x; - e += b; - } while (b > epsilon); - while (square-- != 0) { - e *= e; - } - } else { - e = x > 0 ? DBL_MAX : 0; - } - return e; -} - -double fs_modf(double value, double *iptr) -{ - double a, b; - const double c = value; - - if (0 > c) { - value = -value; - } - if (DBL_MAX >= value) { - for (*iptr = 0; value >= 1; value -= b) { - a = value / 2; - b = 1; - while (a >= b) { - b *= 2; - } - *iptr += b; - } - } else { - *iptr = value; - value = 0; - } - if (0 > c) { - *iptr = -*iptr; - value = -value; - } - return value; -} - -double fs_fmod(double x, double y) -{ - double a, b; - const double c = x; - - if (0 > c) { - x = -x; - } - if (0 > y) { - y = -y; - } - if (y != 0 && DBL_MAX >= y && DBL_MAX >= x) { - while (x >= y) { - a = x / 2; - b = y; - while (a >= b) { - b *= 2; - } - x -= b; - } - } else { - x = 0; - } - return 0 > c ? -x : x; -} - -double fs_pow(double x, double y) -{ - double p = 0; - - if (0 > x && fs_fmod(y, 1) == 0) { - if (fs_fmod(y, 2) == 0) { - p = fs_exp(fs_log(-x) * y); - } else { - p = -fs_exp(fs_log(-x) * y); - } - } else { - if (x != 0 || 0 >= y) { - p = fs_exp(fs_log( x) * y); - } - } - return p; -} - -static double fs_pi(void) -{ - unsigned n; - double a, b, epsilon; - static double p; - static int initialized; - - if (!initialized) { - initialized = 1; - epsilon = DBL_EPSILON / 4; - n = 1; - a = 3; - do { - a /= 9; - b = a / n; - n += 2; - a /= 9; - b -= a / n; - n += 2; - p += b; - } while (b > epsilon); - epsilon = DBL_EPSILON / 2; - n = 1; - a = 2; - do { - a /= 4; - b = a / n; - n += 2; - a /= 4; - b -= a / n; - n += 2; - p += b; - } while (b > epsilon); - p *= 4; - } - return p; -} - -double fs_cos(double x) -{ - unsigned n; - int negative, sine; - double a, b, c; - static double pi, two_pi, half_pi, third_pi, epsilon; - static int initialized; - - if (0 > x) { - x = -x; - } - if (DBL_MAX >= x) { - if (!initialized) { - initialized = 1; - pi = fs_pi(); - two_pi = 2 * pi; - half_pi = pi / 2; - third_pi = pi / 3; - epsilon = DBL_EPSILON / 2; - } - if (x > two_pi) { - x = fs_fmod(x, two_pi); - } - if (x > pi) { - x = two_pi - x; - } - if (x > half_pi) { - x = pi - x; - negative = 1; - } else { - negative = 0; - } - if (x > third_pi) { - x = half_pi - x; - sine = 1; - } else { - sine = 0; - } - c = x * x; - x = n = 0; - a = 1; - do { - b = a; - a *= c; - a /= ++n; - a /= ++n; - b -= a; - a *= c; - a /= ++n; - a /= ++n; - x += b; - } while (b > epsilon); - if (sine) { - x = fs_sqrt((1 - x) * (1 + x)); - } - if (negative) { - x = -x; - } - } else { - x = -DBL_MAX; - } - return x; -} - -double fs_log2(double x) -{ - static double log_2; - static int initialized; - - if (!initialized) { - initialized = 1; - log_2 = fs_log(2); - } - return x > 0 && DBL_MAX >= x ? fs_log(x) / log_2 : fs_log(x); -} - -double fs_exp2(double x) -{ - static double log_2; - static int initialized; - - if (!initialized) { - initialized = 1; - log_2 = fs_log(2); - } - return fs_exp(x * log_2); -} - -long double fs_powl(long double x, long double y) -{ - long double p; - - if (0 > x && fs_fmodl(y, 1) == 0) { - if (fs_fmodl(y, 2) == 0) { - p = fs_expl(fs_logl(-x) * y); - } else { - p = -fs_expl(fs_logl(-x) * y); - } - } else { - if (x != 0 || 0 >= y) { - p = fs_expl(fs_logl( x) * y); - } else { - p = 0; - } - } - return p; -} - -long double fs_sqrtl(long double x) -{ - long int n; - long double a, b; - - if (x > 0 && LDBL_MAX >= x) { - for (n = 0; x > 2; x /= 4) { - ++n; - } - while (0.5 > x) { - --n; - x *= 4; - } - a = x; - b = (1 + x) / 2; - do { - x = b; - b = (a / x + x) / 2; - } while (x > b); - while (n > 0) { - x *= 2; - --n; - } - while (0 > n) { - x /= 2; - ++n; - } - } else { - if (x != 0) { - x = LDBL_MAX; - } - } - return x; -} - -long double fs_logl(long double x) -{ - long int n; - long double a, b, c, epsilon; - static long double A, B, C; - static int initialized; - - if (x > 0 && LDBL_MAX >= x) { - if (!initialized) { - initialized = 1; - B = 1.5; - do { - A = B; - B = 1 / A + A / 2; - } while (A > B); - B /= 2; - C = fs_logl(A); - } - for (n = 0; x > A; x /= 2) { - ++n; - } - while (B > x) { - --n; - x *= 2; - } - a = (x - 1) / (x + 1); - x = C * n + a; - c = a * a; - n = 1; - epsilon = LDBL_EPSILON * x; - if (0 > a) { - if (epsilon > 0) { - epsilon = -epsilon; - } - do { - n += 2; - a *= c; - b = a / n; - x += b; - } while (epsilon > b); - } else { - if (0 > epsilon) { - epsilon = -epsilon; - } - do { - n += 2; - a *= c; - b = a / n; - x += b; - } while (b > epsilon); - } - x *= 2; - } else { - x = -LDBL_MAX; - } - return x; -} - -long double fs_expl(long double x) -{ - long unsigned n, square; - long double b, e; - static long double x_max, x_min, epsilon; - static int initialized; - - if (!initialized) { - initialized = 1; - x_max = fs_logl(LDBL_MAX); - x_min = fs_logl(LDBL_MIN); - epsilon = LDBL_EPSILON / 4; - } - if (x_max >= x && x >= x_min) { - for (square = 0; x > 1; x /= 2) { - ++square; - } - while (-1 > x) { - ++square; - x /= 2; - } - e = b = n = 1; - do { - b /= n++; - b *= x; - e += b; - b /= n++; - b *= x; - e += b; - } while (b > epsilon); - while (square-- != 0) { - e *= e; - } - } else { - e = x > 0 ? LDBL_MAX : 0; - } - return e; -} - -static long double fs_pil(void) -{ - long unsigned n; - long double a, b, epsilon; - static long double p; - static int initialized; - - if (!initialized) { - initialized = 1; - epsilon = LDBL_EPSILON / 4; - n = 1; - a = 3; - do { - a /= 9; - b = a / n; - n += 2; - a /= 9; - b -= a / n; - n += 2; - p += b; - } while (b > epsilon); - epsilon = LDBL_EPSILON / 2; - n = 1; - a = 2; - do { - a /= 4; - b = a / n; - n += 2; - a /= 4; - b -= a / n; - n += 2; - p += b; - } while (b > epsilon); - p *= 4; - } - return p; -} - -long double fs_cosl(long double x) -{ - long unsigned n; - int negative, sine; - long double a, b, c; - static long double pi, two_pi, half_pi, third_pi, epsilon; - static int initialized; - - if (0 > x) { - x = -x; - } - if (LDBL_MAX >= x) { - if (!initialized) { - initialized = 1; - pi = fs_pil(); - two_pi = 2 * pi; - half_pi = pi / 2; - third_pi = pi / 3; - epsilon = LDBL_EPSILON / 2; - } - if (x > two_pi) { - x = fs_fmodl(x, two_pi); - } - if (x > pi) { - x = two_pi - x; - } - if (x > half_pi) { - x = pi - x; - negative = 1; - } else { - negative = 0; - } - if (x > third_pi) { - x = half_pi - x; - sine = 1; - } else { - sine = 0; - } - c = x * x; - x = n = 0; - a = 1; - do { - b = a; - a *= c; - a /= ++n; - a /= ++n; - b -= a; - a *= c; - a /= ++n; - a /= ++n; - x += b; - } while (b > epsilon); - if (sine) { - x = fs_sqrtl((1 - x) * (1 + x)); - } - if (negative) { - x = -x; - } - } else { - x = -LDBL_MAX; - } - return x; -} - -long double fs_fmodl(long double x, long double y) -{ - long double a, b; - const long double c = x; - - if (0 > c) { - x = -x; - } - if (0 > y) { - y = -y; - } - if (y != 0 && LDBL_MAX >= y && LDBL_MAX >= x) { - while (x >= y) { - a = x / 2; - b = y; - while (a >= b) { - b *= 2; - } - x -= b; - } - } else { - x = 0; - } - return 0 > c ? -x : x; -} - -/* END fs_math.c */ +/** + * This code is available at + * http://www.mindspring.com/~pfilandr/C/fs_math/ + * and it is believed to be public domain. + */ + +/* BEGIN fs_math.c */ + +#include "libs/fs_math.h" + +#include +/* +** pi == (atan(1.0 / 3) + atan(1.0 / 2)) * 4 +*/ +static double fs_pi(void); +static long double fs_pil(void); + +double fs_sqrt(double x) +{ + int n; + double a, b; + + if (x > 0 && DBL_MAX >= x) { + for (n = 0; x > 2; x /= 4) { + ++n; + } + while (0.5 > x) { + --n; + x *= 4; + } + a = x; + b = (1 + x) / 2; + do { + x = b; + b = (a / x + x) / 2; + } while (x > b); + while (n > 0) { + x *= 2; + --n; + } + while (0 > n) { + x /= 2; + ++n; + } + } else { + if (x != 0) { + x = DBL_MAX; + } + } + return x; +} + +double fs_log(double x) +{ + int n; + double a, b, c, epsilon; + static double A, B, C; + static int initialized; + + if (x > 0 && DBL_MAX >= x) { + if (!initialized) { + initialized = 1; + A = fs_sqrt(2); + B = A / 2; + C = fs_log(A); + } + for (n = 0; x > A; x /= 2) { + ++n; + } + while (B > x) { + --n; + x *= 2; + } + a = (x - 1) / (x + 1); + x = C * n + a; + c = a * a; + n = 1; + epsilon = DBL_EPSILON * x; + if (0 > a) { + if (epsilon > 0) { + epsilon = -epsilon; + } + do { + n += 2; + a *= c; + b = a / n; + x += b; + } while (epsilon > b); + } else { + if (0 > epsilon) { + epsilon = -epsilon; + } + do { + n += 2; + a *= c; + b = a / n; + x += b; + } while (b > epsilon); + } + x *= 2; + } else { + x = -DBL_MAX; + } + return x; +} + +double fs_log10(double x) +{ + static double log_10; + static int initialized; + + if (!initialized) { + initialized = 1; + log_10 = fs_log(10); + } + return x > 0 && DBL_MAX >= x ? fs_log(x) / log_10 : fs_log(x); +} + +double fs_exp(double x) +{ + unsigned n, square; + double b, e; + static double x_max, x_min, epsilon; + static int initialized; + + if (!initialized) { + initialized = 1; + x_max = fs_log(DBL_MAX); + x_min = fs_log(DBL_MIN); + epsilon = DBL_EPSILON / 4; + } + if (x_max >= x && x >= x_min) { + for (square = 0; x > 1; x /= 2) { + ++square; + } + while (-1 > x) { + ++square; + x /= 2; + } + e = b = n = 1; + do { + b /= n++; + b *= x; + e += b; + b /= n++; + b *= x; + e += b; + } while (b > epsilon); + while (square-- != 0) { + e *= e; + } + } else { + e = x > 0 ? DBL_MAX : 0; + } + return e; +} + +double fs_modf(double value, double *iptr) +{ + double a, b; + const double c = value; + + if (0 > c) { + value = -value; + } + if (DBL_MAX >= value) { + for (*iptr = 0; value >= 1; value -= b) { + a = value / 2; + b = 1; + while (a >= b) { + b *= 2; + } + *iptr += b; + } + } else { + *iptr = value; + value = 0; + } + if (0 > c) { + *iptr = -*iptr; + value = -value; + } + return value; +} + +double fs_fmod(double x, double y) +{ + double a, b; + const double c = x; + + if (0 > c) { + x = -x; + } + if (0 > y) { + y = -y; + } + if (y != 0 && DBL_MAX >= y && DBL_MAX >= x) { + while (x >= y) { + a = x / 2; + b = y; + while (a >= b) { + b *= 2; + } + x -= b; + } + } else { + x = 0; + } + return 0 > c ? -x : x; +} + +double fs_pow(double x, double y) +{ + double p = 0; + + if (0 > x && fs_fmod(y, 1) == 0) { + if (fs_fmod(y, 2) == 0) { + p = fs_exp(fs_log(-x) * y); + } else { + p = -fs_exp(fs_log(-x) * y); + } + } else { + if (x != 0 || 0 >= y) { + p = fs_exp(fs_log( x) * y); + } + } + return p; +} + +static double fs_pi(void) +{ + unsigned n; + double a, b, epsilon; + static double p; + static int initialized; + + if (!initialized) { + initialized = 1; + epsilon = DBL_EPSILON / 4; + n = 1; + a = 3; + do { + a /= 9; + b = a / n; + n += 2; + a /= 9; + b -= a / n; + n += 2; + p += b; + } while (b > epsilon); + epsilon = DBL_EPSILON / 2; + n = 1; + a = 2; + do { + a /= 4; + b = a / n; + n += 2; + a /= 4; + b -= a / n; + n += 2; + p += b; + } while (b > epsilon); + p *= 4; + } + return p; +} + +double fs_cos(double x) +{ + unsigned n; + int negative, sine; + double a, b, c; + static double pi, two_pi, half_pi, third_pi, epsilon; + static int initialized; + + if (0 > x) { + x = -x; + } + if (DBL_MAX >= x) { + if (!initialized) { + initialized = 1; + pi = fs_pi(); + two_pi = 2 * pi; + half_pi = pi / 2; + third_pi = pi / 3; + epsilon = DBL_EPSILON / 2; + } + if (x > two_pi) { + x = fs_fmod(x, two_pi); + } + if (x > pi) { + x = two_pi - x; + } + if (x > half_pi) { + x = pi - x; + negative = 1; + } else { + negative = 0; + } + if (x > third_pi) { + x = half_pi - x; + sine = 1; + } else { + sine = 0; + } + c = x * x; + x = n = 0; + a = 1; + do { + b = a; + a *= c; + a /= ++n; + a /= ++n; + b -= a; + a *= c; + a /= ++n; + a /= ++n; + x += b; + } while (b > epsilon); + if (sine) { + x = fs_sqrt((1 - x) * (1 + x)); + } + if (negative) { + x = -x; + } + } else { + x = -DBL_MAX; + } + return x; +} + +double fs_log2(double x) +{ + static double log_2; + static int initialized; + + if (!initialized) { + initialized = 1; + log_2 = fs_log(2); + } + return x > 0 && DBL_MAX >= x ? fs_log(x) / log_2 : fs_log(x); +} + +double fs_exp2(double x) +{ + static double log_2; + static int initialized; + + if (!initialized) { + initialized = 1; + log_2 = fs_log(2); + } + return fs_exp(x * log_2); +} + +long double fs_powl(long double x, long double y) +{ + long double p; + + if (0 > x && fs_fmodl(y, 1) == 0) { + if (fs_fmodl(y, 2) == 0) { + p = fs_expl(fs_logl(-x) * y); + } else { + p = -fs_expl(fs_logl(-x) * y); + } + } else { + if (x != 0 || 0 >= y) { + p = fs_expl(fs_logl( x) * y); + } else { + p = 0; + } + } + return p; +} + +long double fs_sqrtl(long double x) +{ + long int n; + long double a, b; + + if (x > 0 && LDBL_MAX >= x) { + for (n = 0; x > 2; x /= 4) { + ++n; + } + while (0.5 > x) { + --n; + x *= 4; + } + a = x; + b = (1 + x) / 2; + do { + x = b; + b = (a / x + x) / 2; + } while (x > b); + while (n > 0) { + x *= 2; + --n; + } + while (0 > n) { + x /= 2; + ++n; + } + } else { + if (x != 0) { + x = LDBL_MAX; + } + } + return x; +} + +long double fs_logl(long double x) +{ + long int n; + long double a, b, c, epsilon; + static long double A, B, C; + static int initialized; + + if (x > 0 && LDBL_MAX >= x) { + if (!initialized) { + initialized = 1; + B = 1.5; + do { + A = B; + B = 1 / A + A / 2; + } while (A > B); + B /= 2; + C = fs_logl(A); + } + for (n = 0; x > A; x /= 2) { + ++n; + } + while (B > x) { + --n; + x *= 2; + } + a = (x - 1) / (x + 1); + x = C * n + a; + c = a * a; + n = 1; + epsilon = LDBL_EPSILON * x; + if (0 > a) { + if (epsilon > 0) { + epsilon = -epsilon; + } + do { + n += 2; + a *= c; + b = a / n; + x += b; + } while (epsilon > b); + } else { + if (0 > epsilon) { + epsilon = -epsilon; + } + do { + n += 2; + a *= c; + b = a / n; + x += b; + } while (b > epsilon); + } + x *= 2; + } else { + x = -LDBL_MAX; + } + return x; +} + +long double fs_expl(long double x) +{ + long unsigned n, square; + long double b, e; + static long double x_max, x_min, epsilon; + static int initialized; + + if (!initialized) { + initialized = 1; + x_max = fs_logl(LDBL_MAX); + x_min = fs_logl(LDBL_MIN); + epsilon = LDBL_EPSILON / 4; + } + if (x_max >= x && x >= x_min) { + for (square = 0; x > 1; x /= 2) { + ++square; + } + while (-1 > x) { + ++square; + x /= 2; + } + e = b = n = 1; + do { + b /= n++; + b *= x; + e += b; + b /= n++; + b *= x; + e += b; + } while (b > epsilon); + while (square-- != 0) { + e *= e; + } + } else { + e = x > 0 ? LDBL_MAX : 0; + } + return e; +} + +static long double fs_pil(void) +{ + long unsigned n; + long double a, b, epsilon; + static long double p; + static int initialized; + + if (!initialized) { + initialized = 1; + epsilon = LDBL_EPSILON / 4; + n = 1; + a = 3; + do { + a /= 9; + b = a / n; + n += 2; + a /= 9; + b -= a / n; + n += 2; + p += b; + } while (b > epsilon); + epsilon = LDBL_EPSILON / 2; + n = 1; + a = 2; + do { + a /= 4; + b = a / n; + n += 2; + a /= 4; + b -= a / n; + n += 2; + p += b; + } while (b > epsilon); + p *= 4; + } + return p; +} + +long double fs_cosl(long double x) +{ + long unsigned n; + int negative, sine; + long double a, b, c; + static long double pi, two_pi, half_pi, third_pi, epsilon; + static int initialized; + + if (0 > x) { + x = -x; + } + if (LDBL_MAX >= x) { + if (!initialized) { + initialized = 1; + pi = fs_pil(); + two_pi = 2 * pi; + half_pi = pi / 2; + third_pi = pi / 3; + epsilon = LDBL_EPSILON / 2; + } + if (x > two_pi) { + x = fs_fmodl(x, two_pi); + } + if (x > pi) { + x = two_pi - x; + } + if (x > half_pi) { + x = pi - x; + negative = 1; + } else { + negative = 0; + } + if (x > third_pi) { + x = half_pi - x; + sine = 1; + } else { + sine = 0; + } + c = x * x; + x = n = 0; + a = 1; + do { + b = a; + a *= c; + a /= ++n; + a /= ++n; + b -= a; + a *= c; + a /= ++n; + a /= ++n; + x += b; + } while (b > epsilon); + if (sine) { + x = fs_sqrtl((1 - x) * (1 + x)); + } + if (negative) { + x = -x; + } + } else { + x = -LDBL_MAX; + } + return x; +} + +long double fs_fmodl(long double x, long double y) +{ + long double a, b; + const long double c = x; + + if (0 > c) { + x = -x; + } + if (0 > y) { + y = -y; + } + if (y != 0 && LDBL_MAX >= y && LDBL_MAX >= x) { + while (x >= y) { + a = x / 2; + b = y; + while (a >= b) { + b *= 2; + } + x -= b; + } + } else { + x = 0; + } + return 0 > c ? -x : x; +} + +/* END fs_math.c */ diff --git a/code/espurna/libs/fs_math.h b/code/espurna/libs/fs_math.h index 1884fcdd..9cd0991e 100644 --- a/code/espurna/libs/fs_math.h +++ b/code/espurna/libs/fs_math.h @@ -1,116 +1,116 @@ -/** - * This code is available at - * http://www.mindspring.com/~pfilandr/C/fs_math/ - * and it is believed to be public domain. - */ - -/* BEGIN fs_math.h */ -/* -** Portable freestanding code. -*/ -#ifndef H_FS_MATH_H -#define H_FS_MATH_H - -double fs_sqrt(double x); -double fs_log(double x); -double fs_log10(double x); -/* -** exp(x) = 1 + x + x^2/2! + x^3/3! + ... -*/ -double fs_exp(double x); -double fs_modf(double value, double *iptr); -double fs_fmod(double x, double y); -double fs_pow(double x, double y); -double fs_cos(double x); -/* -** C99 -*/ -double fs_log2(double x); -double fs_exp2(double x); -long double fs_powl(long double x, long double y); -long double fs_sqrtl(long double x); -long double fs_logl(long double x); -long double fs_expl(long double x); -long double fs_cosl(long double x); -long double fs_fmodl(long double x, long double y); - -#endif - -/* END fs_math.h */ - -#if 0 - -/* -> > Anybody know where I can get some source code for a -> > reasonably fast double -> > precision square root algorithm in C. -> > I'm looking for one that is not IEEE -> > compliant as I am running on a Z/OS mainframe. -> > -> > I would love to use the standard library but -> > unfortunatly I'm using a -> > stripped down version of C that looses the the runtime library -> > (we have to write our own). -> -> long double Ssqrt(long double x) -> { -> long double a, b; -> size_t c; - -size_t is a bug here. -c needs to be a signed type: - long c; - -> if (x > 0) { -> c = 0; -> while (x > 4) { -> x /= 4; -> ++c; -> } -> while (1.0 / 4 > x) { -> x *= 4; -> --c; -> } -> a = x; -> b = ((4 > a) + a) / 2; - -Not a bug, but should be: - b = (1 + a) / 2; - -> do { -> x = b; -> b = (a / x + x) / 2; -> } while (x > b); -> if (c > 0) { - -The above line is why c needs to be a signed type, -otherwise the decremented values of c, are greater than zero, -and the function won't work if the initial value of x -is less than 0.25 - -> while (c--) { -> x *= 2; -> } -> } else { -> while (c++) { -> x /= 2; -> } -> } -> } -> return x; -> } - -> -> > -> > That algorithm was actually 4 times slower -> > then the one below, and more -> > code. It was accurate though. -> > -> -> Sorry Pete, I wasn't looking very carefully. -> When I converted your function -> to double precision it's was much quicker, the best I've seen yet. - -*/ - -#endif +/** + * This code is available at + * http://www.mindspring.com/~pfilandr/C/fs_math/ + * and it is believed to be public domain. + */ + +/* BEGIN fs_math.h */ +/* +** Portable freestanding code. +*/ +#ifndef H_FS_MATH_H +#define H_FS_MATH_H + +double fs_sqrt(double x); +double fs_log(double x); +double fs_log10(double x); +/* +** exp(x) = 1 + x + x^2/2! + x^3/3! + ... +*/ +double fs_exp(double x); +double fs_modf(double value, double *iptr); +double fs_fmod(double x, double y); +double fs_pow(double x, double y); +double fs_cos(double x); +/* +** C99 +*/ +double fs_log2(double x); +double fs_exp2(double x); +long double fs_powl(long double x, long double y); +long double fs_sqrtl(long double x); +long double fs_logl(long double x); +long double fs_expl(long double x); +long double fs_cosl(long double x); +long double fs_fmodl(long double x, long double y); + +#endif + +/* END fs_math.h */ + +#if 0 + +/* +> > Anybody know where I can get some source code for a +> > reasonably fast double +> > precision square root algorithm in C. +> > I'm looking for one that is not IEEE +> > compliant as I am running on a Z/OS mainframe. +> > +> > I would love to use the standard library but +> > unfortunatly I'm using a +> > stripped down version of C that looses the the runtime library +> > (we have to write our own). +> +> long double Ssqrt(long double x) +> { +> long double a, b; +> size_t c; + +size_t is a bug here. +c needs to be a signed type: + long c; + +> if (x > 0) { +> c = 0; +> while (x > 4) { +> x /= 4; +> ++c; +> } +> while (1.0 / 4 > x) { +> x *= 4; +> --c; +> } +> a = x; +> b = ((4 > a) + a) / 2; + +Not a bug, but should be: + b = (1 + a) / 2; + +> do { +> x = b; +> b = (a / x + x) / 2; +> } while (x > b); +> if (c > 0) { + +The above line is why c needs to be a signed type, +otherwise the decremented values of c, are greater than zero, +and the function won't work if the initial value of x +is less than 0.25 + +> while (c--) { +> x *= 2; +> } +> } else { +> while (c++) { +> x /= 2; +> } +> } +> } +> return x; +> } + +> +> > +> > That algorithm was actually 4 times slower +> > then the one below, and more +> > code. It was accurate though. +> > +> +> Sorry Pete, I wasn't looking very carefully. +> When I converted your function +> to double precision it's was much quicker, the best I've seen yet. + +*/ + +#endif diff --git a/code/espurna/libs/pwm.h b/code/espurna/libs/pwm.h index 488a129c..a1c73c97 100755 --- a/code/espurna/libs/pwm.h +++ b/code/espurna/libs/pwm.h @@ -1,45 +1,45 @@ -/* - * Copyright (C) 2016 Stefan Brüns - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __PWM_H__ -#define __PWM_H__ - -/*SUPPORT UP TO 8 PWM CHANNEL*/ -#ifndef PWM_CHANNEL_NUM_MAX -#define PWM_CHANNEL_NUM_MAX 8 -#endif - -struct pwm_param { - uint32 period; - uint32 freq; - uint32 duty[PWM_CHANNEL_NUM_MAX]; //PWM_CHANNEL<=8 -}; - -/* pwm_init should be called only once, for now */ -void pwm_init(uint32 period, uint32 *duty,uint32 pwm_channel_num,uint32 (*pin_info_list)[3]); -void pwm_start(void); - -void pwm_set_duty(uint32 duty, uint8 channel); -uint32 pwm_get_duty(uint8 channel); -void pwm_set_period(uint32 period); -uint32 pwm_get_period(void); - -uint32 get_pwm_version(void); -void set_pwm_debug_en(uint8 print_en); - -#endif +/* + * Copyright (C) 2016 Stefan Brüns + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __PWM_H__ +#define __PWM_H__ + +/*SUPPORT UP TO 8 PWM CHANNEL*/ +#ifndef PWM_CHANNEL_NUM_MAX +#define PWM_CHANNEL_NUM_MAX 8 +#endif + +struct pwm_param { + uint32 period; + uint32 freq; + uint32 duty[PWM_CHANNEL_NUM_MAX]; //PWM_CHANNEL<=8 +}; + +/* pwm_init should be called only once, for now */ +void pwm_init(uint32 period, uint32 *duty,uint32 pwm_channel_num,uint32 (*pin_info_list)[3]); +void pwm_start(void); + +void pwm_set_duty(uint32 duty, uint8 channel); +uint32 pwm_get_duty(uint8 channel); +void pwm_set_period(uint32 period); +uint32 pwm_get_period(void); + +uint32 get_pwm_version(void); +void set_pwm_debug_en(uint8 print_en); + +#endif diff --git a/code/test/build/garland.h b/code/test/build/garland.h index 94b55f98..4a0bd646 100644 --- a/code/test/build/garland.h +++ b/code/test/build/garland.h @@ -1 +1 @@ -#define GARLAND_SUPPORT 1 +#define GARLAND_SUPPORT 1