1#include <math.h>
2
3/*
4special cases:
5        logb(+-0) = -inf, and raise divbyzero
6        logb(+-inf) = +inf
7        logb(nan) = nan
8*/
9
10double logb(double x) {
11    if (!isfinite(x))
12        return x * x;
13    if (x == 0)
14        return -1 / (x * x);
15    return ilogb(x);
16}
17