1 int fpclassify(float x)
13 return !(isnan(x) || isinf(x));
17 return (x != 0) && (x + x == x);
21 return !(x + x == x + x);
34 return log(x + sqrt(x*x - 1));
38 return log(x + sqrt(x*x + 1));
42 return 0.5 * log((1+x) / (1-x));
46 return 0.5 * (exp(x) + exp(-x));
50 return 0.5 * (exp(x) - exp(-x));
54 return sinh(x) / cosh(x);
80 return floor(log2(fabs(x)));
82 float ldexp(float x, int e)
88 return log(x) * M_LOG10E;
96 return log(x) * M_LOG2E;
100 return floor(log2(fabs(x)));
104 return '1 0 0' * (f - trunc(f)) + '0 1 0' * trunc(f);
107 float scalbn(float x, int n)
109 return x * pow(2, n);
114 return copysign(pow(fabs(x), 1.0/3.0), x);
116 float hypot(float x, float y)
118 return sqrt(x*x + y*y);
123 // approximation taken from wikipedia
126 return copysign(sqrt(1 - exp(-y * (1.273239544735163 + 0.14001228868667 * y) / (1 + 0.14001228868667 * y))), x);
132 vector lgamma(float x)
134 // TODO improve accuracy
136 return fabs(x) * '1 0 0' + copysign(1, x) * '0 1 0';
137 if(x < 1 && x == floor(x))
138 return nan("gamma") * '1 1 1';
143 // reflection formula:
144 // gamma(1-z) * gamma(z) = pi / sin(pi*z)
145 // lgamma(1-z) + lgamma(z) = log(pi) - log(sin(pi*z))
146 // sign of gamma(1-z) = sign of gamma(z) * sign of sin(pi*z)
148 v_x = log(M_PI) - log(fabs(v_z)) - v_x;
155 return lgamma(x + 1) - log(x) * '1 0 0';
157 return (0.5 * log(2 * M_PI * x) + x * (log(x) - 1)) * '1 0 0' + '0 1 0';
159 float tgamma(float x)
163 return exp(v_x) * v_y;
166 float nearbyint(float x)
172 return (x>=0) ? floor(x) : ceil(x);
175 float fmod(float x, float y)
177 return x - y * trunc(x / y);
179 float remainder(float x, float y)
181 return x - y * rint(x / y);
183 vector remquo(float x, float y)
192 float copysign(float x, float y)
194 return fabs(x) * ((y>0) ? 1 : -1);
196 float nan(string tag)
200 float nextafter(float x, float y)
204 return nan("nextafter");
206 return -nextafter(-x, -y);
207 // now we know that x < y
208 // so we need the next number > x
210 d = max(fabs(x), 0.00000000000000000000001);
221 float nexttoward(float x, float y)
223 return nextafter(x, y);
226 float fdim(float x, float y)
230 float fmax(float x, float y)
234 float fmin(float x, float y)
238 float fma(float x, float y, float z)
243 int isgreater(float x, float y)
247 int isgreaterequal(float x, float y)
251 int isless(float x, float y)
255 int islessequal(float x, float y)
259 int islessgreater(float x, float y)
261 return x < y || x > y;
263 int isunordered(float x, float y)
265 return !(x < y || x == y || x > y);