Blame src/math/fenvutil.c

nsz ce441c
#include <fenv.h>
nsz ce441c
#include <stdio.h>
nsz ce441c
#include "fenvutil.h"
nsz ce441c
nsz ce441c
static struct {
nsz ce441c
	int flag;
nsz ce441c
	char *s;
nsz ce441c
} eflags[] = {
nsz ce441c
	{FE_INVALID, "FE_INVALID"},
nsz ce441c
	{FE_DIVBYZERO, "FE_DIVBYZERO"},
nsz ce441c
	{FE_OVERFLOW, "FE_OVERFLOW"},
nsz ce441c
	{FE_UNDERFLOW, "FE_UNDERFLOW"},
nsz ce441c
	{FE_INEXACT, "FE_INEXACT"},
nsz ce441c
};
nsz ce441c
static int ne = sizeof eflags / sizeof *eflags;
nsz ce441c
nsz ce441c
static struct {
nsz ce441c
	int flag;
nsz ce441c
	char *s;
nsz ce441c
} rflags[] = {
nsz ce441c
	{FE_TONEAREST,"FE_TONEAREST"},
nsz ce441c
	{FE_DOWNWARD,"FE_DOWNWARD"},
nsz ce441c
	{FE_UPWARD,"FE_UPWARD"},
nsz ce441c
	{FE_TOWARDZERO,"FE_TOWARDZERO"},
nsz ce441c
};
nsz ce441c
static int nr = sizeof rflags / sizeof *rflags;
nsz ce441c
nsz ce441c
char *strexcept(int f) {
nsz ce441c
	static char buf[256];
nsz ce441c
	char *p;
nsz ce441c
	int i, all=0;
nsz ce441c
nsz ce441c
	p = buf;
nsz ce441c
	for (i = 0; i < ne; i++)
nsz ce441c
		if (f & eflags[i].flag) {
nsz ce441c
			p += sprintf(p, "%s%s", all ? "|" : "", eflags[i].s);
nsz ce441c
			all |= eflags[i].flag;
nsz ce441c
		}
nsz ce441c
	if (all != f) {
nsz ce441c
		p += sprintf(p, "%s%d", all ? "|" : "", f & ~all);
nsz ce441c
		all = f;
nsz ce441c
	}
nsz ce441c
	p += sprintf(p, "%s", all ? "" : "0");
nsz ce441c
	return buf;
nsz ce441c
}
nsz ce441c
nsz ce441c
char *strround(int f) {
nsz ce441c
	static char buf[256];
nsz ce441c
	int i;
nsz ce441c
nsz ce441c
	for (i = 0; i < nr; i++)
nsz ce441c
		if (f == rflags[i].flag) {
nsz ce441c
			sprintf(buf, "%s", rflags[i].s);
nsz ce441c
			return buf;
nsz ce441c
		}
nsz ce441c
	sprintf(buf, "%d", f);
nsz ce441c
	return buf;
nsz ce441c
}
nsz ce441c