Merge from mainline
[official-gcc.git] / libdecnumber / decLibrary.c
blob19468ac892ea67a0050a863effc4d24e6c515311
1 /* Temporary library support for decimal floating point.
2 Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA. */
21 #include "config.h"
22 #include "decContext.h"
23 #include "decimal128.h"
24 #include "decimal64.h"
25 #include "decimal32.h"
27 void __host_to_ieee_32 (_Decimal32, decimal32 *);
28 void __host_to_ieee_64 (_Decimal64, decimal64 *);
29 void __host_to_ieee_128 (_Decimal128, decimal128 *);
31 extern int isinfd32 (_Decimal32);
32 extern int isinfd64 (_Decimal64);
33 extern int isinfd128 (_Decimal128);
34 extern void __dfp_enable_traps (void);
35 extern void __dfp_raise (int exception __attribute__ ((unused)));
37 int
38 isinfd32 (_Decimal32 arg)
40 decNumber dn;
41 decimal32 d32;
43 __host_to_ieee_32 (arg, &d32);
44 decimal32ToNumber (&d32, &dn);
45 return (decNumberIsInfinite (&dn));
48 int
49 isinfd64 (_Decimal64 arg)
51 decNumber dn;
52 decimal64 d64;
54 __host_to_ieee_64 (arg, &d64);
55 decimal64ToNumber (&d64, &dn);
56 return (decNumberIsInfinite (&dn));
59 int
60 isinfd128 (_Decimal128 arg)
62 decNumber dn;
63 decimal128 d128;
65 __host_to_ieee_128 (arg, &d128);
66 decimal128ToNumber (&d128, &dn);
67 return (decNumberIsInfinite (&dn));
70 int __dfp_traps;
72 void
73 __dfp_enable_traps (void)
75 __dfp_traps = 1;
78 void
79 __dfp_raise (int exception __attribute__ ((unused)))
81 raise (SIGFPE);
84 uint32_t
85 __dec_byte_swap (uint32_t in)
87 uint32_t out = 0;
88 unsigned char *p = (unsigned char *) &out;
89 union {
90 uint32_t i;
91 unsigned char b[4];
92 } u;
94 u.i = in;
95 p[0] = u.b[3];
96 p[1] = u.b[2];
97 p[2] = u.b[1];
98 p[3] = u.b[0];
100 return out;