2.9
[glibc/nacl-glibc.git] / sysdeps / sparc / sparc32 / soft-fp / q_util.c
blob41ecd685dffe988aa4ae8919c7c50a9ddeb84383
1 /* Software floating-point emulation.
2 Helper routine for _Q_* routines.
3 Simulate exceptions using double arithmetics.
4 Copyright (C) 1999 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
6 Contributed by Jakub Jelinek (jj@ultra.linux.cz).
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, write to the Free
20 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 02111-1307 USA. */
23 #include "soft-fp.h"
25 unsigned long long ___Q_numbers [] = {
26 0x0000000000000000ULL, /* Zero */
27 0x0010100000000000ULL, /* Very tiny number */
28 0x0010000000000000ULL, /* Minimum normalized number */
29 0x7fef000000000000ULL, /* A huge double number */
32 double ___Q_simulate_exceptions(int exceptions)
34 double d, *p = (double *)___Q_numbers;
35 if (exceptions & FP_EX_INVALID)
36 d = p[0]/p[0];
37 if (exceptions & FP_EX_OVERFLOW)
39 d = p[3] + p[3];
40 exceptions &= ~FP_EX_INEXACT;
42 if (exceptions & FP_EX_UNDERFLOW)
44 if (exceptions & FP_EX_INEXACT)
46 d = p[2] * p[2];
47 exceptions &= ~FP_EX_INEXACT;
49 else
50 d = p[1] - p[2];
52 if (exceptions & FP_EX_DIVZERO)
53 d = 1.0/p[0];
54 if (exceptions & FP_EX_INEXACT)
55 d = p[3] - p[2];
56 return d;