Back to index

glibc  2.9
q_util.c
Go to the documentation of this file.
00001 /* Software floating-point emulation.
00002    Helper routine for _q_* routines.
00003    Simulate exceptions using double arithmetics.
00004    Copyright (C) 1999, 2000 Free Software Foundation, Inc.
00005    This file is part of the GNU C Library.
00006    Contributed by Jakub Jelinek (jj@ultra.linux.cz).
00007 
00008    The GNU C Library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Lesser General Public
00010    License as published by the Free Software Foundation; either
00011    version 2.1 of the License, or (at your option) any later version.
00012 
00013    The GNU C Library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Lesser General Public License for more details.
00017 
00018    You should have received a copy of the GNU Lesser General Public
00019    License along with the GNU C Library; if not, write to the Free
00020    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00021    02111-1307 USA.  */
00022 
00023 #include "soft-fp.h"
00024 
00025 unsigned long long ___q_numbers [] = {
00026 0x0000000000000000ULL, /* Zero */
00027 0x0010100000000000ULL, /* Very tiny number */
00028 0x0010000000000000ULL, /* Minimum normalized number */
00029 0x7fef000000000000ULL, /* A huge double number */
00030 };
00031 
00032 double ___q_simulate_exceptions(int exceptions)
00033 {
00034   double d, *p = (double *)___q_numbers;
00035   if (exceptions & FP_EX_INVALID)
00036     d = p[0]/p[0];
00037   if (exceptions & FP_EX_OVERFLOW)
00038     {
00039       d = p[3] + p[3];
00040       exceptions &= ~FP_EX_INEXACT;
00041     }
00042   if (exceptions & FP_EX_UNDERFLOW)
00043     {
00044       if (exceptions & FP_EX_INEXACT)
00045         {
00046          d = p[2] * p[2];
00047          exceptions &= ~FP_EX_INEXACT;
00048        }
00049       else
00050        d = p[1] - p[2];
00051     }
00052   if (exceptions & FP_EX_DIVZERO)
00053     d = 1.0/p[0];
00054   if (exceptions & FP_EX_INEXACT)
00055     d = p[3] - p[2];
00056   return d;
00057 }