NOTE => NOTES
[AROS.git] / arch / m68k-all / mlib / fenv.c
blobb3d25bdcaab7e01d93722177542ada005111512e
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;
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 = __excepts;
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;
74 return 0;
77 /* Determine which of subset of the exceptions specified by EXCEPTS are
78 currently set. */
79 int fetestexcept (int __excepts)
81 return (fe_env.__status_register & __excepts);
84 /* Store the current floating-point environment in the object pointed
85 to by ENVP. */
86 int fegetenv (fenv_t *envp)
88 *envp = fe_env;
89 return 0;
92 /* Save the current environment in the object pointed to by ENVP, clear
93 exception flags and install a non-stop mode (if available) for all
94 exceptions. */
95 int feholdexcept (fenv_t *envp)
97 *envp = fe_env;
98 errno = 0;
99 return 0;
102 /* Establish the floating-point environment represented by the object
103 pointed to by ENVP. */
104 int fesetenv(const fenv_t *envp)
106 fe_env = *envp;
107 return 0;
110 /* Save current exceptions in temporary storage, install environment
111 represented by object pointed to by ENVP and raise exceptions
112 according to saved exceptions. */
113 int feupdateenv(const fenv_t *envp)
115 int fexcept = fe_env.__status_register;
116 fesetenv(envp);
117 feraiseexcept(fexcept);
118 return 0;