1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 #include <fenv.h> 7 #include <float.h> 8 #include <stdio.h> 9 #include "dsp_test_util.h" 10 11 int dsp_util_has_denormal() 12 { 13 float x = 1; 14 while (x >= FLT_MIN) 15 x /= 2; 16 return x > 0; 17 } 18 19 void dsp_util_clear_fp_exceptions() 20 { 21 feclearexcept(FE_ALL_EXCEPT); 22 } 23 24 void dsp_util_print_fp_exceptions() 25 { 26 int excepts = fetestexcept(FE_ALL_EXCEPT); 27 printf("floating-point exceptions: "); 28 if (excepts & FE_DIVBYZERO) 29 printf("FE_DIVBYZERO "); 30 if (excepts & FE_INVALID) 31 printf("FE_INVALID "); 32 if (excepts & FE_OVERFLOW) 33 printf("FE_OVERFLOW "); 34 if (excepts & FE_UNDERFLOW) 35 printf("FE_UNDERFLOW "); 36 printf("\n"); 37 } 38