1 /* Copyright (C) 2007-2016 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 3, or (at your option) any later
10 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
24 #define decimal64FromString __dpd64FromString
25 #define decimal64ToString __dpd64ToString
26 #define decimal64ToEngString __dpd64ToEngString
27 #define decimal64FromNumber __dpd64FromNumber
28 #define decimal64ToNumber __dpd64ToNumber
30 #include "dpd/decimal64.c"
32 #undef decimal64FromString
33 #undef decimal64ToString
34 #undef decimal64ToEngString
35 #undef decimal64FromNumber
36 #undef decimal64ToNumber
41 #define decimal64FromString __decimal64FromString
42 #define decimal64ToString __decimal64ToString
43 #define decimal64ToEngString __decimal64ToEngString
44 #define decimal64FromNumber __decimal64FromNumber
45 #define decimal64ToNumber __decimal64ToNumber
48 decimal64
*decimal64FromString (decimal64
*, const char *, decContext
*);
49 char *decimal64ToString (const decimal64
*, char *);
50 char *decimal64ToEngString (const decimal64
*, char *);
51 decimal64
*decimal64FromNumber (decimal64
*, const decNumber
*, decContext
*);
52 decNumber
*decimal64ToNumber (const decimal64
*, decNumber
*);
54 void __host_to_ieee_64 (_Decimal64 in
, decimal64
*out
);
55 void __ieee_to_host_64 (decimal64 in
, _Decimal64
*out
);
58 decimal64FromNumber (decimal64
*d64
, const decNumber
*dn
,
61 /* decimal64 and _Decimal64 are different types. */
68 __dpd64FromNumber (d64
, dn
, set
);
70 /* __dpd64FromNumber returns in big endian. But _dpd_to_bid64 takes
72 __ieee_to_host_64 (*d64
, &u
._Dec
);
74 /* Convert DPD to BID. */
75 _dpd_to_bid64 (&u
._Dec
, &u
._Dec
);
77 /* dfp.c is in bid endian. */
78 __host_to_ieee_64 (u
._Dec
, &u
.dec
);
80 /* d64 is returned as a pointer to _Decimal64 here. */
87 decimal64ToNumber (const decimal64
*bid64
, decNumber
*dn
)
89 /* decimal64 and _Decimal64 are different types. */
96 /* bid64 is a pointer to _Decimal64 in bid endian. But _bid_to_dpd64
98 __ieee_to_host_64 (*bid64
, &u
._Dec
);
100 /* Convert BID to DPD. */
101 _bid_to_dpd64 (&u
._Dec
, &u
._Dec
);
103 /* __dpd64ToNumber is in bid endian. */
104 __host_to_ieee_64 (u
._Dec
, &u
.dec
);
106 return __dpd64ToNumber (&u
.dec
, dn
);
110 decimal64ToString (const decimal64
*d64
, char *string
)
112 decNumber dn
; /* work */
113 decimal64ToNumber (d64
, &dn
);
114 decNumberToString (&dn
, string
);
119 decimal64ToEngString (const decimal64
*d64
, char *string
)
121 decNumber dn
; /* work */
122 decimal64ToNumber (d64
, &dn
);
123 decNumberToEngString (&dn
, string
);
128 decimal64FromString (decimal64
*result
, const char *string
,
131 decContext dc
; /* work */
132 decNumber dn
; /* .. */
134 decContextDefault (&dc
, DEC_INIT_DECIMAL64
); /* no traps, please */
135 dc
.round
= set
->round
; /* use supplied rounding */
137 decNumberFromString (&dn
, string
, &dc
); /* will round if needed */
138 decimal64FromNumber (result
, &dn
, &dc
);
140 { /* something happened */
141 decContextSetStatus (set
, dc
.status
); /* .. pass it on */