Back to index

glibc  2.9
fraiseexcpt.c
Go to the documentation of this file.
00001 /* Raise given exceptions.
00002    Copyright (C) 1997,1999-2002, 2008 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <fenv_libc.h>
00021 #include <bp-sym.h>
00022 
00023 #undef feraiseexcept
00024 int
00025 __feraiseexcept (int excepts)
00026 {
00027   fenv_union_t u;
00028 
00029   /* Raise exceptions represented by EXCEPTS.  It is the responsibility of
00030      the OS to ensure that if multiple exceptions occur they are fed back
00031      to this process in the proper way; this can happen in hardware,
00032      anyway (in particular, inexact with overflow or underflow). */
00033 
00034   /* Get the current state.  */
00035   u.fenv = fegetenv_register ();
00036 
00037   /* Add the exceptions */
00038   u.l[1] = (u.l[1]
00039            | (excepts & FPSCR_STICKY_BITS)
00040            /* Turn FE_INVALID into FE_INVALID_SOFTWARE.  */
00041            | (excepts >> ((31 - FPSCR_VX) - (31 - FPSCR_VXSOFT))
00042               & FE_INVALID_SOFTWARE));
00043 
00044   /* Store the new status word (along with the rest of the environment),
00045      triggering any appropriate exceptions.  */
00046   fesetenv_register (u.fenv);
00047 
00048   if ((excepts & FE_INVALID))
00049     {
00050       /* For some reason, some PowerPC chips (the 601, in particular)
00051         don't have FE_INVALID_SOFTWARE implemented.  Detect this
00052         case and raise FE_INVALID_SNAN instead.  */
00053       u.fenv = fegetenv_register ();
00054       if ((u.l[1] & FE_INVALID) == 0)
00055        set_fpscr_bit (FPSCR_VXSNAN);
00056     }
00057 
00058   /* Success.  */
00059   return 0;
00060 }
00061 
00062 #include <shlib-compat.h>
00063 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
00064 strong_alias (__feraiseexcept, __old_feraiseexcept)
00065 compat_symbol (libm, BP_SYM (__old_feraiseexcept), BP_SYM (feraiseexcept), GLIBC_2_1);
00066 #endif
00067 
00068 libm_hidden_ver (__feraiseexcept, feraiseexcept)
00069 versioned_symbol (libm, BP_SYM (__feraiseexcept), BP_SYM (feraiseexcept), GLIBC_2_2);