2 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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
21 /* As a special exception, if you link this library with other files,
22 some of which are compiled with GCC, to produce an executable,
23 this library does not by itself cause the resulting executable
24 to be covered by the GNU General Public License.
25 This exception does not however invalidate any other reasons why
26 the executable file might be covered by the GNU General Public License. */
28 #define decimal32FromString __dpd32FromString
29 #define decimal32ToString __dpd32ToString
30 #define decimal32ToEngString __dpd32ToEngString
31 #define decimal32FromNumber __dpd32FromNumber
32 #define decimal32ToNumber __dpd32ToNumber
34 #include "dpd/decimal32.c"
36 #undef decimal32FromString
37 #undef decimal32ToString
38 #undef decimal32ToEngString
39 #undef decimal32FromNumber
40 #undef decimal32ToNumber
45 #define decimal32FromString __decimal32FromString
46 #define decimal32ToString __decimal32ToString
47 #define decimal32ToEngString __decimal32ToEngString
48 #define decimal32FromNumber __decimal32FromNumber
49 #define decimal32ToNumber __decimal32ToNumber
52 decimal32
*decimal32FromString (decimal32
*, const char *, decContext
*);
53 char *decimal32ToString (const decimal32
*, char *);
54 char *decimal32ToEngString (const decimal32
*, char *);
55 decimal32
*decimal32FromNumber (decimal32
*, const decNumber
*, decContext
*);
56 decNumber
*decimal32ToNumber (const decimal32
*, decNumber
*);
58 void __host_to_ieee_32 (_Decimal32 in
, decimal32
*out
);
59 void __ieee_to_host_32 (decimal32 in
, _Decimal32
*out
);
62 decimal32FromNumber (decimal32
*d32
, const decNumber
*dn
,
65 /* decimal32 and _Decimal32 are different types. */
72 __dpd32FromNumber (d32
, dn
, set
);
74 /* __dpd32FromNumber returns in big endian. But _dpd_to_bid32 takes
76 __ieee_to_host_32 (*d32
, &u
._Dec
);
78 /* Convert DPD to BID. */
79 _dpd_to_bid32 (&u
._Dec
, &u
._Dec
);
81 /* dfp.c is in bid endian. */
82 __host_to_ieee_32 (u
._Dec
, &u
.dec
);
84 /* d32 is returned as a pointer to _Decimal32 here. */
91 decimal32ToNumber (const decimal32
*bid32
, decNumber
*dn
)
93 /* decimal32 and _Decimal32 are different types. */
100 /* bid32 is a pointer to _Decimal32 in bid endian. But _bid_to_dpd32
101 takes host endian. */
102 __ieee_to_host_32 (*bid32
, &u
._Dec
);
104 /* Convert BID to DPD. */
105 _bid_to_dpd32 (&u
._Dec
, &u
._Dec
);
107 /* __dpd32ToNumber is in bid endian. */
108 __host_to_ieee_32 (u
._Dec
, &u
.dec
);
110 return __dpd32ToNumber (&u
.dec
, dn
);
114 decimal32ToString (const decimal32
*d32
, char *string
)
116 decNumber dn
; /* work */
117 decimal32ToNumber (d32
, &dn
);
118 decNumberToString (&dn
, string
);
123 decimal32ToEngString (const decimal32
*d32
, char *string
)
125 decNumber dn
; /* work */
126 decimal32ToNumber (d32
, &dn
);
127 decNumberToEngString (&dn
, string
);
132 decimal32FromString (decimal32
*result
, const char *string
,
135 decContext dc
; /* work */
136 decNumber dn
; /* .. */
138 decContextDefault (&dc
, DEC_INIT_DECIMAL32
); /* no traps, please */
139 dc
.round
= set
->round
; /* use supplied rounding */
141 decNumberFromString (&dn
, string
, &dc
); /* will round if needed */
142 decimal32FromNumber (result
, &dn
, &dc
);
144 { /* something happened */
145 decContextSetStatus (set
, dc
.status
); /* .. pass it on */