1/*-
2 * Copyright (c) 2010 by Peter Jeremy <peterjeremy@acm.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
23 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26/*
27===============================================================================
28
29This C source file is part of TestFloat, Release 2a, a package of programs
30for testing the correctness of floating-point arithmetic complying to the
31IEC/IEEE Standard for Floating-Point.
32
33Written by John R. Hauser.  More information is available through the Web
34page `http://HTTP.CS.Berkeley.EDU/~jhauser/arithmetic/TestFloat.html'.
35
36THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort
37has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
38TIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO
39PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
40AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
41
42Derivative works are acceptable, even for commercial purposes, so long as
43(1) they include prominent notice that the work is derivative, and (2) they
44include prominent notice akin to these four paragraphs for those parts of
45this code that are retained.
46
47===============================================================================
48*/
49
50#include <sys/cdefs.h>
51__FBSDID("$FreeBSD$");
52
53#pragma STDC FENV_ACCESS ON
54#include <fenv.h>
55#include <ieeefp.h>
56#include "milieu.h"
57#include "systflags.h"
58
59/*
60-------------------------------------------------------------------------------
61Clears the system's IEC/IEEE floating-point exception flags.  Returns the
62previous value of the flags.
63-------------------------------------------------------------------------------
64*/
65int8 syst_float_flags_clear( void )
66{
67    fexcept_t flags;
68
69    fegetexceptflag(&flags, FE_ALL_EXCEPT);
70    feclearexcept(FE_ALL_EXCEPT);
71    return (flags >> 5);
72}
73
74