1 int fpclassify(float x)
13 return !(isnan(x) || isinf(x));
17 return (x != 0) && (x + x == x);
36 return log(x + sqrt(x*x - 1));
40 return log(x + sqrt(x*x + 1));
44 return 0.5 * log((1+x) / (1-x));
48 return 0.5 * (exp(x) + exp(-x));
52 return 0.5 * (exp(x) - exp(-x));
56 return sinh(x) / cosh(x);
82 return floor(log2(fabs(x)));
84 float ldexp(float x, int e)
90 return log(x) * M_LOG10E;
98 return log(x) * M_LOG2E;
102 return floor(log2(fabs(x)));
106 return '1 0 0' * (f - trunc(f)) + '0 1 0' * trunc(f);
109 float scalbn(float x, int n)
111 return x * pow(2, n);
116 return copysign(pow(fabs(x), 1.0/3.0), x);
118 float hypot(float x, float y)
120 return sqrt(x*x + y*y);
125 // approximation taken from wikipedia
128 return copysign(sqrt(1 - exp(-y * (1.273239544735163 + 0.14001228868667 * y) / (1 + 0.14001228868667 * y))), x);
134 vector lgamma(float x)
136 // TODO improve accuracy
138 return fabs(x) * '1 0 0' + copysign(1, x) * '0 1 0';
139 if(x < 1 && x == floor(x))
140 return nan("gamma") * '1 1 1';
145 // reflection formula:
146 // gamma(1-z) * gamma(z) = pi / sin(pi*z)
147 // lgamma(1-z) + lgamma(z) = log(pi) - log(sin(pi*z))
148 // sign of gamma(1-z) = sign of gamma(z) * sign of sin(pi*z)
150 v_x = log(M_PI) - log(fabs(v_z)) - v_x;
157 return lgamma(x + 1) - log(x) * '1 0 0';
159 return (0.5 * log(2 * M_PI * x) + x * (log(x) - 1)) * '1 0 0' + '0 1 0';
161 float tgamma(float x)
165 return exp(v_x) * v_y;
168 float nearbyint(float x)
174 return (x>=0) ? floor(x) : ceil(x);
177 float fmod(float x, float y)
179 return x - y * trunc(x / y);
181 float remainder(float x, float y)
183 return x - y * rint(x / y);
185 vector remquo(float x, float y)
194 float copysign(float x, float y)
196 return fabs(x) * ((y>0) ? 1 : -1);
198 float nan(string tag)
202 float nextafter(float x, float y)
206 return nan("nextafter");
208 return -nextafter(-x, -y);
209 // now we know that x < y
210 // so we need the next number > x
212 d = max(fabs(x), 0.00000000000000000000001);
223 float nexttoward(float x, float y)
225 return nextafter(x, y);
228 float fdim(float x, float y)
232 float fmax(float x, float y)
236 float fmin(float x, float y)
240 float fma(float x, float y, float z)
245 int isgreater(float x, float y)
249 int isgreaterequal(float x, float y)
253 int isless(float x, float y)
257 int islessequal(float x, float y)
261 int islessgreater(float x, float y)
263 return x < y || x > y;
265 int isunordered(float x, float y)
267 return !(x < y || x == y || x > y);