Back to index

glibc  2.9
fraiseexcpt.c
Go to the documentation of this file.
00001 /* Raise given exceptions.
00002    Copyright (C) 1997,99,2000,01,02 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <fenv.h>
00022 #include <float.h>
00023 #include <math.h>
00024 
00025 int
00026 __feraiseexcept (int excepts)
00027 {
00028   /* Raise exceptions represented by EXCEPTS.  But we must raise only one
00029      signal at a time.  It is important that if the overflow/underflow
00030      exception and the divide by zero exception are given at the same
00031      time, the overflow/underflow exception follows the divide by zero
00032      exception.  */
00033 
00034   /* First: invalid exception.  */
00035   if (excepts & FE_INVALID)
00036     {
00037       /* One example of a invalid operation is 0 * Infinity.  */
00038       double d = HUGE_VAL;
00039       __asm__ __volatile__ ("fmul%.s %#0r0,%0; fnop" : "=f" (d) : "0" (d));
00040     }
00041 
00042   /* Next: division by zero.  */
00043   if (excepts & FE_DIVBYZERO)
00044     {
00045       double d = 1.0;
00046       __asm__ __volatile__ ("fdiv%.s %#0r0,%0; fnop" : "=f" (d) : "0" (d));
00047     }
00048 
00049   /* Next: overflow.  */
00050   if (excepts & FE_OVERFLOW)
00051     {
00052       long double d = LDBL_MAX;
00053 
00054       __asm__ __volatile__ ("fmul%.x %0,%0; fnop" : "=f" (d) : "0" (d));
00055     }
00056 
00057   /* Next: underflow.  */
00058   if (excepts & FE_UNDERFLOW)
00059     {
00060       long double d = -LDBL_MAX;
00061 
00062       __asm__ __volatile__ ("fetox%.x %0; fnop" : "=f" (d) : "0" (d));
00063     }
00064 
00065   /* Last: inexact.  */
00066   if (excepts & FE_INEXACT)
00067     {
00068       long double d = 1.0;
00069       __asm__ __volatile__ ("fdiv%.s %#0r3,%0; fnop" : "=f" (d) : "0" (d));
00070     }
00071 
00072   /* Success.  */
00073   return 0;
00074 }
00075 
00076 #include <shlib-compat.h>
00077 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
00078 strong_alias (__feraiseexcept, __old_feraiseexcept)
00079 compat_symbol (libm, __old_feraiseexcept, feraiseexcept, GLIBC_2_1);
00080 #endif
00081 
00082 libm_hidden_ver (__feraiseexcept, feraiseexcept)
00083 versioned_symbol (libm, __feraiseexcept, feraiseexcept, GLIBC_2_2);