summaryrefslogtreecommitdiff
path: root/cras/src/dsp/tests/dsp_test_util.c
blob: e52a481a8983bbd66e879bc9cfb74f20bfbbf74a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <fenv.h>
#include <float.h>
#include <stdio.h>
#include "dsp_test_util.h"

int dsp_util_has_denormal()
{
	float x = 1;
	while (x >= FLT_MIN)
		x /= 2;
	return x > 0;
}

void dsp_util_clear_fp_exceptions()
{
	feclearexcept(FE_ALL_EXCEPT);
}

void dsp_util_print_fp_exceptions()
{
	int excepts = fetestexcept(FE_ALL_EXCEPT);
	printf("floating-point exceptions: ");
	if (excepts & FE_DIVBYZERO)
		printf("FE_DIVBYZERO ");
	if (excepts & FE_INVALID)
		printf("FE_INVALID ");
	if (excepts & FE_OVERFLOW)
		printf("FE_OVERFLOW ");
	if (excepts & FE_UNDERFLOW)
		printf("FE_UNDERFLOW ");
	printf("\n");
}