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