2014-12-22 12:35:05 +01:00
|
|
|
#include "c_math.h"
|
|
|
|
#include "c_types.h"
|
2015-02-05 05:26:20 +01:00
|
|
|
#include "user_config.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
|
2015-01-26 12:57:54 +01:00
|
|
|
double floor(double x)
|
|
|
|
{
|
2016-08-19 08:35:35 +02:00
|
|
|
return (double) (x < 0.f ? ((int) x == x ? x : (((int) x) - 1)) : ((int) x));
|
2015-01-25 21:15:54 +01:00
|
|
|
}
|
|
|
|
|
2015-01-26 12:57:54 +01:00
|
|
|
#define MAXEXP 2031 /* (MAX_EXP * 16) - 1 */
|
|
|
|
#define MINEXP -2047 /* (MIN_EXP * 16) - 1 */
|
2015-01-25 21:15:54 +01:00
|
|
|
#define HUGE MAXFLOAT
|
2015-02-05 03:20:20 +01:00
|
|
|
|
2015-02-05 05:26:20 +01:00
|
|
|
double a1[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR =
|
2015-02-05 03:20:20 +01:00
|
|
|
{
|
|
|
|
1.0,
|
|
|
|
0.95760328069857365,
|
|
|
|
0.91700404320467123,
|
|
|
|
0.87812608018664974,
|
|
|
|
0.84089641525371454,
|
|
|
|
0.80524516597462716,
|
|
|
|
0.77110541270397041,
|
|
|
|
0.73841307296974966,
|
|
|
|
0.70710678118654752,
|
|
|
|
0.67712777346844637,
|
|
|
|
0.64841977732550483,
|
|
|
|
0.62092890603674203,
|
|
|
|
0.59460355750136054,
|
|
|
|
0.56939431737834583,
|
|
|
|
0.54525386633262883,
|
|
|
|
0.52213689121370692,
|
|
|
|
0.50000000000000000
|
|
|
|
};
|
2015-02-05 05:26:20 +01:00
|
|
|
double a2[] ICACHE_STORE_ATTR ICACHE_RODATA_ATTR =
|
2015-02-05 03:20:20 +01:00
|
|
|
{
|
|
|
|
0.24114209503420288E-17,
|
|
|
|
0.92291566937243079E-18,
|
|
|
|
-0.15241915231122319E-17,
|
|
|
|
-0.35421849765286817E-17,
|
|
|
|
-0.31286215245415074E-17,
|
|
|
|
-0.44654376565694490E-17,
|
|
|
|
0.29306999570789681E-17,
|
|
|
|
0.11260851040933474E-17
|
|
|
|
};
|
2015-02-10 17:39:03 +01:00
|
|
|
double p1 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.833333333333332114e-1;
|
|
|
|
double p2 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.125000000005037992e-1;
|
|
|
|
double p3 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.223214212859242590e-2;
|
|
|
|
double p4 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.434457756721631196e-3;
|
|
|
|
double q1 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.693147180559945296e0;
|
|
|
|
double q2 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.240226506959095371e0;
|
|
|
|
double q3 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.555041086640855953e-1;
|
|
|
|
double q4 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.961812905951724170e-2;
|
|
|
|
double q5 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.133335413135857847e-2;
|
|
|
|
double q6 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.154002904409897646e-3;
|
|
|
|
double q7 ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.149288526805956082e-4;
|
|
|
|
double k ICACHE_STORE_ATTR ICACHE_RODATA_ATTR = 0.442695040888963407;
|
2015-02-05 03:20:20 +01:00
|
|
|
|
2015-02-05 03:06:22 +01:00
|
|
|
double pow(double x, double y)
|
|
|
|
{
|
2015-01-25 21:15:54 +01:00
|
|
|
double frexp(), g, ldexp(), r, u1, u2, v, w, w1, w2, y1, y2, z;
|
|
|
|
int iw1, m, p;
|
2016-09-07 22:45:06 +02:00
|
|
|
bool flipsignal = false;
|
2015-01-25 21:15:54 +01:00
|
|
|
|
|
|
|
if (y == 0.0)
|
2015-01-26 12:57:54 +01:00
|
|
|
return (1.0);
|
|
|
|
if (x <= 0.0)
|
|
|
|
{
|
|
|
|
if (x == 0.0)
|
|
|
|
{
|
|
|
|
if (y > 0.0)
|
2016-09-07 22:45:06 +02:00
|
|
|
return 0.0;
|
2015-01-26 12:57:54 +01:00
|
|
|
//cmemsg(FP_POWO, &y);
|
|
|
|
//return(HUGE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//cmemsg(FP_POWN, &x);
|
|
|
|
x = -x;
|
2016-09-07 22:45:06 +02:00
|
|
|
|
|
|
|
if (y != (int) y) { // if y is fractional, then this woud result in a complex number
|
|
|
|
return NAN;
|
|
|
|
}
|
|
|
|
flipsignal = ((int) y) & 1;
|
2015-01-26 12:57:54 +01:00
|
|
|
}
|
2015-01-25 21:15:54 +01:00
|
|
|
}
|
|
|
|
g = frexp(x, &m);
|
|
|
|
p = 0;
|
|
|
|
if (g <= a1[8])
|
2015-01-26 12:57:54 +01:00
|
|
|
p = 8;
|
2015-01-25 21:15:54 +01:00
|
|
|
if (g <= a1[p + 4])
|
2015-01-26 12:57:54 +01:00
|
|
|
p += 4;
|
2015-01-25 21:15:54 +01:00
|
|
|
if (g <= a1[p + 2])
|
2015-01-26 12:57:54 +01:00
|
|
|
p += 2;
|
2015-01-25 21:15:54 +01:00
|
|
|
p++;
|
|
|
|
z = ((g - a1[p]) - a2[p / 2]) / (g + a1[p]);
|
|
|
|
z += z;
|
|
|
|
v = z * z;
|
|
|
|
r = (((p4 * v + p3) * v + p2) * v + p1) * v * z;
|
|
|
|
r += k * r;
|
|
|
|
u2 = (r + z * k) + z;
|
|
|
|
u1 = 0.0625 * (double)(16 * m - p);
|
|
|
|
y1 = 0.0625 * (double)((int)(16.0 * y));
|
|
|
|
y2 = y - y1;
|
|
|
|
w = u2 * y + u1 * y2;
|
|
|
|
w1 = 0.0625 * (double)((int)(16.0 * w));
|
|
|
|
w2 = w - w1;
|
|
|
|
w = w1 + u1 * y1;
|
|
|
|
w1 = 0.0625 * (double)((int)(16.0 * w));
|
|
|
|
w2 += (w - w1);
|
|
|
|
w = 0.0625 * (double)((int)(16.0 * w2));
|
|
|
|
iw1 = 16.0 * (w1 + w);
|
|
|
|
w2 -= w;
|
2015-01-26 12:57:54 +01:00
|
|
|
while (w2 > 0.0)
|
|
|
|
{
|
|
|
|
iw1++;
|
|
|
|
w2 -= 0.0625;
|
2015-01-25 21:15:54 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
if (iw1 > MAXEXP)
|
|
|
|
{
|
|
|
|
//cmemsg(FP_POWO, &y);
|
|
|
|
return (HUGE);
|
2015-01-25 21:15:54 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
if (iw1 < MINEXP)
|
|
|
|
{
|
|
|
|
//cmemsg(FP_POWU, &y);
|
|
|
|
return (0.0);
|
2015-01-25 21:15:54 +01:00
|
|
|
}
|
|
|
|
m = iw1 / 16;
|
|
|
|
if (iw1 >= 0)
|
2015-01-26 12:57:54 +01:00
|
|
|
m++;
|
2015-01-25 21:15:54 +01:00
|
|
|
p = 16 * m - iw1;
|
2015-01-26 12:57:54 +01:00
|
|
|
z = ((((((q7 * w2 + q6) * w2 + q5) * w2 + q4) * w2 + q3) * w2 + q2) * w2 + q1) * w2;
|
2015-01-25 21:15:54 +01:00
|
|
|
z = a1[p] + a1[p] * z;
|
2016-09-07 22:45:06 +02:00
|
|
|
double res = ldexp(z, m);
|
|
|
|
return flipsignal ? -res : res;
|
2015-01-25 21:15:54 +01:00
|
|
|
}
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
#if 0
|
|
|
|
#ifndef __math_68881
|
2015-01-26 12:57:54 +01:00
|
|
|
double atan(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double cos(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double sin(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double tan(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double tanh(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double frexp(double x, int *y)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double modf(double x, double *y)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double ceil(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double fabs(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double floor(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
|
|
|
#endif /* ! defined (__math_68881) */
|
|
|
|
|
|
|
|
/* Non reentrant ANSI C functions. */
|
|
|
|
|
|
|
|
#ifndef _REENT_ONLY
|
|
|
|
#ifndef __math_68881
|
2015-01-26 12:57:54 +01:00
|
|
|
double acos(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double asin(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double atan2(double x, double y)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double cosh(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double sinh(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double exp(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double ldexp(double x, int y)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double log(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double log10(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double pow(double x, double y)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double sqrt(double x)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-26 12:57:54 +01:00
|
|
|
double fmod(double x, double y)
|
|
|
|
{
|
|
|
|
return x;
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
|
|
|
#endif /* ! defined (__math_68881) */
|
|
|
|
#endif /* ! defined (_REENT_ONLY) */
|
|
|
|
#endif
|