5 int fpclassify(float e)
15 bool isfinite(float e)
17 return !(isnan(e) || isinf(e));
21 return (e != 0) && (e + e == e);
28 bool isnormal(float e)
39 return log(e + sqrt(e*e - 1));
43 return log(e + sqrt(e*e + 1));
47 return 0.5 * log((1+e) / (1-e));
51 return 0.5 * (exp(e) + exp(-e));
55 return 0.5 * (exp(e) - exp(-e));
59 return sinh(e) / cosh(e);
80 v.x = e / POW(2, v.y);
85 return floor(log2(fabs(e)));
87 float ldexp(float e, int e)
91 float logn(float e, float base)
93 return log(e) / log(base);
97 return log(e) * M_LOG10E;
105 return log(e) * M_LOG2E;
109 return floor(log2(fabs(e)));
113 return '1 0 0' * (f - trunc(f)) + '0 1 0' * trunc(f);
116 float scalbn(float e, int n)
118 return e * POW(2, n);
123 return copysign(POW(fabs(e), (1.0/3.0)), e);
125 float hypot(float e, float f)
127 return sqrt(e*e + f*f);
132 // approximation taken from wikipedia
135 return copysign(sqrt(1 - exp(-f * (1.273239544735163 + 0.14001228868667 * f) / (1 + 0.14001228868667 * f))), e);
141 vector lgamma(float e)
143 // TODO improve accuracy
145 return fabs(e) * '1 0 0' + copysign(1, e) * '0 1 0';
146 if(e < 1 && e == floor(e))
147 return nan("gamma") * '1 1 1';
152 // reflection formula:
153 // gamma(1-z) * gamma(z) = pi / sin(pi*z)
154 // lgamma(1-z) + lgamma(z) = log(pi) - log(sin(pi*z))
155 // sign of gamma(1-z) = sign of gamma(z) * sign of sin(pi*z)
157 v.x = log(M_PI) - log(fabs(v.z)) - v.x;
164 return lgamma(e + 1) - log(e) * '1 0 0';
166 return (0.5 * log(2 * M_PI * e) + e * (log(e) - 1)) * '1 0 0' + '0 1 0';
168 float tgamma(float e)
170 vector v = lgamma(e);
171 return exp(v.x) * v.y;
183 float pymod(float e, float f)
185 return e - f * floor(e / f);
188 float nearbyint(float e)
194 return (e>=0) ? floor(e) : ceil(e);
197 float fmod(float e, float f)
199 return e - f * trunc(e / f);
201 float remainder(float e, float f)
203 return e - f * rint(e / f);
205 vector remquo(float e, float f)
214 float copysign(float e, float f)
216 return fabs(e) * ((f>0) ? 1 : -1);
218 float nan(string tag)
222 float nextafter(float e, float f)
226 return nan("nextafter");
228 return -nextafter(-e, -f);
229 // now we know that e < f
230 // so we need the next number > e
232 d = max(fabs(e), 0.00000000000000000000001);
243 float nexttoward(float e, float f)
245 return nextafter(e, f);
248 float fdim(float e, float f)
252 float fmax(float e, float f)
256 float fmin(float e, float f)
260 float fma(float e, float f, float g)
265 int isgreater(float e, float f)
269 int isgreaterequal(float e, float f)
273 int isless(float e, float f)
277 int islessequal(float e, float f)
281 int islessgreater(float e, float f)
283 return e < f || e > f;
285 int isunordered(float e, float f)
287 return !(e < f || e == f || e > f);