xref: /netbsd-src/lib/libm/softfloat/feupdateenv.c (revision 7e30e94394d0994ab9534f68a8f91665045c91ce)
1*7e30e943Schs /*	$NetBSD: feupdateenv.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
2*7e30e943Schs 
3*7e30e943Schs /*-
4*7e30e943Schs  * Copyright (c) 2017 The NetBSD Foundation, Inc.
5*7e30e943Schs  * All rights reserved.
6*7e30e943Schs  *
7*7e30e943Schs  * This code is derived from software contributed to The NetBSD Foundation
8*7e30e943Schs  * by Chuck Silvers.
9*7e30e943Schs  *
10*7e30e943Schs  * Redistribution and use in source and binary forms, with or without
11*7e30e943Schs  * modification, are permitted provided that the following conditions
12*7e30e943Schs  * are met:
13*7e30e943Schs  * 1. Redistributions of source code must retain the above copyright
14*7e30e943Schs  *    notice, this list of conditions and the following disclaimer.
15*7e30e943Schs  * 2. Redistributions in binary form must reproduce the above copyright
16*7e30e943Schs  *    notice, this list of conditions and the following disclaimer in the
17*7e30e943Schs  *    documentation and/or other materials provided with the distribution.
18*7e30e943Schs  *
19*7e30e943Schs  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*7e30e943Schs  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*7e30e943Schs  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*7e30e943Schs  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*7e30e943Schs  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*7e30e943Schs  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*7e30e943Schs  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*7e30e943Schs  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*7e30e943Schs  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*7e30e943Schs  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*7e30e943Schs  * POSSIBILITY OF SUCH DAMAGE.
30*7e30e943Schs  */
31*7e30e943Schs 
32*7e30e943Schs #include <sys/cdefs.h>
33*7e30e943Schs __RCSID("$NetBSD: feupdateenv.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
34*7e30e943Schs 
35*7e30e943Schs #include "namespace.h"
36*7e30e943Schs 
37*7e30e943Schs #include <fenv.h>
38*7e30e943Schs #include <ieeefp.h>
39*7e30e943Schs 
40*7e30e943Schs #ifdef __weak_alias
__weak_alias(feupdateenv,_feupdateenv)41*7e30e943Schs __weak_alias(feupdateenv,_feupdateenv)
42*7e30e943Schs #endif
43*7e30e943Schs 
44*7e30e943Schs int
45*7e30e943Schs feupdateenv(const fenv_t *envp)
46*7e30e943Schs {
47*7e30e943Schs 	fexcept_t oflag;
48*7e30e943Schs 
49*7e30e943Schs 	fegetexceptflag(&oflag, FE_ALL_EXCEPT);
50*7e30e943Schs 
51*7e30e943Schs 	fpsetround(__FENV_GET_ROUND(envp));
52*7e30e943Schs 	fpsetmask(__FENV_GET_MASK(envp));
53*7e30e943Schs 	fpsetsticky(__FENV_GET_MASK(envp));
54*7e30e943Schs 
55*7e30e943Schs 	feraiseexcept(oflag);
56*7e30e943Schs 	return 0;
57*7e30e943Schs }
58