Back to index

glibc  2.9
fenv.h
Go to the documentation of this file.
00001 /* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _FENV_H
00020 # error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
00021 #endif
00022 
00023 #include <bits/wordsize.h>
00024 
00025 
00026 /* Define bits representing the exception.  We use the bit positions
00027    of the appropriate accrued exception bits from the FSR.  */
00028 enum
00029   {
00030     FE_INVALID =     (1 << 9),
00031 #define FE_INVALID   FE_INVALID
00032     FE_OVERFLOW =    (1 << 8),
00033 #define FE_OVERFLOW  FE_OVERFLOW
00034     FE_UNDERFLOW =   (1 << 7),
00035 #define FE_UNDERFLOW FE_UNDERFLOW
00036     FE_DIVBYZERO =   (1 << 6),
00037 #define FE_DIVBYZERO FE_DIVBYZERO
00038     FE_INEXACT =     (1 << 5)
00039 #define FE_INEXACT   FE_INEXACT
00040   };
00041 
00042 #define FE_ALL_EXCEPT \
00043        (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
00044 
00045 /* The Sparc FPU supports all of the four defined rounding modes.  We
00046    use again the bit positions in the FPU control word as the values
00047    for the appropriate macros.  */
00048 enum
00049   {
00050     FE_TONEAREST =   (0U << 30),
00051 #define FE_TONEAREST FE_TONEAREST
00052     FE_TOWARDZERO =  (1U << 30),
00053 #define FE_TOWARDZERO       FE_TOWARDZERO
00054     FE_UPWARD =      (2U << 30),
00055 #define FE_UPWARD    FE_UPWARD
00056     FE_DOWNWARD =    (3U << 30)
00057 #define FE_DOWNWARD  FE_DOWNWARD
00058   };
00059 
00060 #define __FE_ROUND_MASK     (3U << 30)
00061 
00062 
00063 /* Type representing exception flags.  */
00064 typedef unsigned long int fexcept_t;
00065 
00066 
00067 /* Type representing floating-point environment.  */
00068 typedef unsigned long int fenv_t;
00069 
00070 /* If the default argument is used we use this value.  */
00071 #define FE_DFL_ENV   ((__const fenv_t *) -1)
00072 
00073 #ifdef __USE_GNU
00074 /* Floating-point environment where none of the exception is masked.  */
00075 # define FE_NOMASK_ENV      ((__const fenv_t *) -2)
00076 #endif
00077 
00078 /* For internal use only: access the fp state register.  */
00079 #if __WORDSIZE == 64
00080 # define __fenv_stfsr(X)   __asm__ ("stx %%fsr,%0" : "=m" (X))
00081 # define __fenv_ldfsr(X)   __asm__ __volatile__ ("ldx %0,%%fsr" : : "m" (X))
00082 #else
00083 # define __fenv_stfsr(X)   __asm__ ("st %%fsr,%0" : "=m" (X))
00084 # define __fenv_ldfsr(X)   __asm__ __volatile__ ("ld %0,%%fsr" : : "m" (X))
00085 #endif