OSDN Git Service

1576f28555e255ceba5128af2d804b0bd587b020
[pf3gnuchains/gcc-fork.git] / libdecnumber / decLibrary.c
1 /* Temporary library support for decimal floating point.
2    Copyright (C) 2005 Free Software Foundation, Inc.
3
4    This file is part of GCC.
5
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.
10
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.
15
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.  */
20
21 #include "config.h"
22 #include "decContext.h"
23 #include "decimal128.h"
24 #include "decimal64.h"
25 #include "decimal32.h"
26
27 void __host_to_ieee_32 (_Decimal32, decimal32 *);
28 void __host_to_ieee_64 (_Decimal64, decimal64 *);
29 void __host_to_ieee_128 (_Decimal128, decimal128 *);
30
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)));
36
37 int
38 isinfd32 (_Decimal32 arg)
39 {
40   decNumber dn;
41   decimal32 d32;
42
43   __host_to_ieee_32 (arg, &d32);
44   decimal32ToNumber (&d32, &dn);
45   return (decNumberIsInfinite (&dn));
46 }
47
48 int
49 isinfd64 (_Decimal64 arg)
50 {
51   decNumber dn;
52   decimal64 d64;
53
54   __host_to_ieee_64 (arg, &d64);
55   decimal64ToNumber (&d64, &dn);
56   return (decNumberIsInfinite (&dn));
57 }
58
59 int
60 isinfd128 (_Decimal128 arg)
61 {
62   decNumber dn;
63   decimal128 d128;
64
65   __host_to_ieee_128 (arg, &d128);
66   decimal128ToNumber (&d128, &dn);
67   return (decNumberIsInfinite (&dn));
68 }
69
70 int __dfp_traps;
71
72 void
73 __dfp_enable_traps (void)
74 {
75   __dfp_traps = 1;
76 }
77
78 void
79 __dfp_raise (int exception __attribute__ ((unused)))
80 {
81   raise (SIGFPE);
82 }
83
84 unsigned long
85 __dec_byte_swap (unsigned long in)
86 {
87   unsigned long out;
88   unsigned char *p = (unsigned char *) &out;
89   union {
90     unsigned long i;
91     unsigned char b[4];
92   } u;
93
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];
99
100   return out;
101 }