use USER_CPPFLAGS
[AROS.git] / arch / m68k-all / stdc / fenv.c
bloba3ecf6d902e43802a771a045e2cc5852735f3b6c
1 /*-
2 * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
3 * All rights reserved.
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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
26 * $FreeBSD: src/lib/msun/arm/fenv.c,v 1.1.20.1 2009/04/15 03:14:26 kensmith Exp $
29 #include <errno.h>
30 #include <fenv.h>
33 * Hopefully the system ID byte is immutable, so it's valid to use
34 * this as a default environment.
36 const fenv_t __fe_dfl_env = { };
37 static fenv_t fe_env;
39 /* FIXME: These are just stubs for the moment for soft-float
40 * A new implemntation is needed for hard-float support
43 /* Clear the supported exceptions represented by EXCEPTS. */
44 int feclearexcept (int __excepts)
46 fe_env.__status_register &= ~(__excepts & FE_ALL_EXCEPT);
47 return 0;
50 /* Store implementation-defined representation of the exception flags
51 indicated by EXCEPTS in the object pointed to by FLAGP. */
52 int fegetexceptflag (fexcept_t *__flagp, int __excepts)
54 *__flagp = (fe_env.__status_register & __excepts & FE_ALL_EXCEPT);
55 return 0;
58 /* Raise the supported exceptions represented by EXCEPTS. */
59 int feraiseexcept (int __excepts)
61 if (__excepts & (FE_UNDERFLOW | FE_OVERFLOW)) {
62 errno = ERANGE;
63 } else if (__excepts) {
64 errno = EDOM;
66 return 0;
69 /* Set complete status for exceptions indicated by EXCEPTS according to
70 the representation in the object pointed to by FLAGP. */
71 int fesetexceptflag(const fexcept_t *flagp, int excepts)
73 fe_env.__status_register &= ~(excepts & FE_ALL_EXCEPT);
74 fe_env.__status_register |= (*flagp & excepts & FE_ALL_EXCEPT);
76 return 0;
79 /* Determine which of subset of the exceptions specified by EXCEPTS are
80 currently set. */
81 int fetestexcept (int __excepts)
83 return (fe_env.__status_register & __excepts & FE_ALL_EXCEPT);
86 /* Store the current floating-point environment in the object pointed
87 to by ENVP. */
88 int fegetenv (fenv_t *envp)
90 *envp = fe_env;
91 return 0;
94 /* Save the current environment in the object pointed to by ENVP, clear
95 exception flags and install a non-stop mode (if available) for all
96 exceptions. */
97 int feholdexcept (fenv_t *envp)
99 *envp = fe_env;
100 errno = 0;
101 return 0;
104 int fegetround(void) {
105 return -1;
108 int fesetround(int round) {
109 return -1;
112 /* Establish the floating-point environment represented by the object
113 pointed to by ENVP. */
114 int fesetenv(const fenv_t *envp)
116 fe_env = *envp;
117 return 0;
120 /* Save current exceptions in temporary storage, install environment
121 represented by object pointed to by ENVP and raise exceptions
122 according to saved exceptions. */
123 int feupdateenv(const fenv_t *envp)
125 int fexcept = fe_env.__status_register;
126 fesetenv(envp);
127 feraiseexcept(fexcept);
128 return 0;