packages feed

altfloat-0.2.2: c99-compat.c

/*
 * Simple implementations of some C99 library functions.
 * Note that the goal of altfloat is not to create a C99 math library: these
 * functions are intended to just be "good enough" on platforms where they are
 * missing.
 *
 * Copyright (C) 2010 Nick Bowler.
 *
 * License BSD2:  2-clause BSD license.  See LICENSE for full terms.
 * This is free software: you are free to change and redistribute it.
 * There is NO WARRANTY, to the extent permitted by law.
 */
#include <config.h>
#include <limits.h>
#include <math.h>

#if NEED_LIBM_NAN
double nan(const char *tagp)
{
	return NAN;
}
#endif

#if NEED_LIBM_LOG2
double log2(double x)
{
	return log(x) / log(2);
}
#endif

#if NEED_LIBM_EXP2
double exp2(double x)
{
	return pow(2, x);
}
#endif

#if NEED_LIBM_FMA
double fma(double x, double y, double z)
{
	return x*y + z;
}
#endif

#if NEED_LIBM_REMQUO
double remquo(double x, double y, int *quo)
{
	unsigned tmp = fabs(round(x/y));
	int sign     = signbit(x/y) ? -1 : 1;

	*quo = sign * (int)(tmp % (INT_MAX + 1u));
	return remainder(x, y);
}
#endif