shithub: npe

ref: e8d44e6791e9568d0a4e3291d15692f9223870f1
dir: /libnpe/log2.c/

View raw version
#include <math.h>
#include "_npe.h"

double
log2(double x)
{
	static double ln2c = 0.0;
	if(x == 0)
		return -hugeD;
	if(x < 0 || isNaN(x))
		return NaN();
	if(ln2c == 0.0)
		ln2c = log(2.0);

	return log(x)/ln2c;
}

float
log2f(float x)
{
	if(x == 0)
		return -hugeF;

	return log2(x);
}