1207151Smarius/*-
2207151Smarius * Copyright (c) 2010 by Peter Jeremy <peterjeremy@acm.org>
3207151Smarius * All rights reserved.
4207151Smarius *
5207151Smarius * Redistribution and use in source and binary forms, with or without
6207151Smarius * modification, are permitted provided that the following conditions
7207151Smarius * are met:
8207151Smarius * 1. Redistributions of source code must retain the above copyright
9207151Smarius *    notice, this list of conditions and the following disclaimer.
10207151Smarius * 2. Redistributions in binary form must reproduce the above copyright
11207151Smarius *    notice, this list of conditions and the following disclaimer in the
12207151Smarius *    documentation and/or other materials provided with the distribution.
13207151Smarius *
14207151Smarius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15207151Smarius * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16207151Smarius * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17207151Smarius * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18207151Smarius * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19207151Smarius * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20207151Smarius * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21207151Smarius * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22207151Smarius * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
23207151Smarius * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24207151Smarius */
25207151Smarius
26207151Smarius/*
27207151Smarius===============================================================================
28207151Smarius
29207151SmariusThis C source file is part of TestFloat, Release 2a, a package of programs
30207151Smariusfor testing the correctness of floating-point arithmetic complying to the
31207151SmariusIEC/IEEE Standard for Floating-Point.
32207151Smarius
33207151SmariusWritten by John R. Hauser.  More information is available through the Web
34207151Smariuspage `http://HTTP.CS.Berkeley.EDU/~jhauser/arithmetic/TestFloat.html'.
35207151Smarius
36207151SmariusTHIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort
37207151Smariushas been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
38207151SmariusTIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO
39207151SmariusPERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
40207151SmariusAND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
41207151Smarius
42207151SmariusDerivative works are acceptable, even for commercial purposes, so long as
43207151Smarius(1) they include prominent notice that the work is derivative, and (2) they
44207151Smariusinclude prominent notice akin to these four paragraphs for those parts of
45207151Smariusthis code that are retained.
46207151Smarius
47207151Smarius===============================================================================
48207151Smarius*/
49207151Smarius
50207151Smarius#include <sys/cdefs.h>
51207151Smarius__FBSDID("$FreeBSD$");
52207151Smarius
53207151Smarius#pragma STDC FENV_ACCESS ON
54207151Smarius#include <fenv.h>
55207151Smarius#include <ieeefp.h>
56207151Smarius#include "milieu.h"
57207151Smarius#include "systflags.h"
58207151Smarius
59207151Smarius/*
60207151Smarius-------------------------------------------------------------------------------
61207151SmariusClears the system's IEC/IEEE floating-point exception flags.  Returns the
62207151Smariusprevious value of the flags.
63207151Smarius-------------------------------------------------------------------------------
64207151Smarius*/
65207151Smariusint8 syst_float_flags_clear( void )
66207151Smarius{
67207151Smarius    fexcept_t flags;
68207151Smarius
69207151Smarius    fegetexceptflag(&flags, FE_ALL_EXCEPT);
70207151Smarius    feclearexcept(FE_ALL_EXCEPT);
71207151Smarius    return (flags >> 5);
72207151Smarius}
73207151Smarius
74