OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.2/] [libdecnumber/] [bid/] [decimal64.c] - Blame information for rev 438

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
/* Copyright (C) 2007, 2009
2
   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 under
7
the terms of the GNU General Public License as published by the Free
8
Software Foundation; either version 3, or (at your option) any later
9
version.
10
 
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
14
for more details.
15
 
16
Under Section 7 of GPL version 3, you are granted additional
17
permissions described in the GCC Runtime Library Exception, version
18
3.1, as published by the Free Software Foundation.
19
 
20
You should have received a copy of the GNU General Public License and
21
a copy of the GCC Runtime Library Exception along with this program;
22
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
<http://www.gnu.org/licenses/>.  */
24
 
25
#define decimal64FromString __dpd64FromString
26
#define decimal64ToString __dpd64ToString
27
#define decimal64ToEngString __dpd64ToEngString
28
#define decimal64FromNumber __dpd64FromNumber
29
#define decimal64ToNumber __dpd64ToNumber
30
 
31
#include "dpd/decimal64.c"
32
 
33
#undef decimal64FromString
34
#undef decimal64ToString
35
#undef decimal64ToEngString
36
#undef decimal64FromNumber
37
#undef decimal64ToNumber
38
 
39
#include "bid-dpd.h"
40
 
41
#ifdef IN_LIBGCC2
42
#define decimal64FromString __decimal64FromString
43
#define decimal64ToString __decimal64ToString
44
#define decimal64ToEngString __decimal64ToEngString
45
#define decimal64FromNumber __decimal64FromNumber
46
#define decimal64ToNumber __decimal64ToNumber
47
#endif
48
 
49
decimal64 *decimal64FromString (decimal64 *, const char *, decContext *);
50
char *decimal64ToString (const decimal64 *, char *);
51
char *decimal64ToEngString (const decimal64 *, char *);
52
decimal64 *decimal64FromNumber (decimal64 *, const decNumber *, decContext *);
53
decNumber *decimal64ToNumber (const decimal64 *, decNumber *);
54
 
55
void __host_to_ieee_64 (_Decimal64 in, decimal64 *out);
56
void __ieee_to_host_64 (decimal64 in, _Decimal64 *out);
57
 
58
decimal64 *
59
decimal64FromNumber (decimal64 *d64, const decNumber *dn,
60
                      decContext *set)
61
{
62
  /* decimal64 and _Decimal64 are different types.  */
63
  union
64
    {
65
      _Decimal64 _Dec;
66
      decimal64 dec;
67
    } u;
68
 
69
  __dpd64FromNumber (d64, dn, set);
70
 
71
  /* __dpd64FromNumber returns in big endian. But _dpd_to_bid64 takes
72
     host endian. */
73
  __ieee_to_host_64 (*d64, &u._Dec);
74
 
75
  /* Convert DPD to BID.  */
76
  _dpd_to_bid64 (&u._Dec, &u._Dec);
77
 
78
  /* dfp.c is in bid endian. */
79
  __host_to_ieee_64 (u._Dec, &u.dec);
80
 
81
  /* d64 is returned as a pointer to _Decimal64 here.  */
82
  *d64 = u.dec;
83
 
84
  return d64;
85
}
86
 
87
decNumber *
88
decimal64ToNumber (const decimal64 *bid64, decNumber *dn)
89
{
90
  /* decimal64 and _Decimal64 are different types.  */
91
  union
92
    {
93
      _Decimal64 _Dec;
94
      decimal64 dec;
95
    } u;
96
 
97
  /* bid64 is a pointer to _Decimal64 in bid endian. But _bid_to_dpd64
98
     takes host endian.  */
99
  __ieee_to_host_64 (*bid64, &u._Dec);
100
 
101
  /* Convert BID to DPD.  */
102
  _bid_to_dpd64 (&u._Dec, &u._Dec);
103
 
104
  /* __dpd64ToNumber is in bid endian.  */
105
  __host_to_ieee_64 (u._Dec, &u.dec);
106
 
107
  return __dpd64ToNumber (&u.dec, dn);
108
}
109
 
110
char *
111
decimal64ToString (const decimal64 *d64, char *string)
112
{
113
  decNumber dn;                 /* work */
114
  decimal64ToNumber (d64, &dn);
115
  decNumberToString (&dn, string);
116
  return string;
117
}
118
 
119
char *
120
decimal64ToEngString (const decimal64 *d64, char *string)
121
{
122
  decNumber dn;                 /* work */
123
  decimal64ToNumber (d64, &dn);
124
  decNumberToEngString (&dn, string);
125
  return string;
126
}
127
 
128
decimal64 *
129
decimal64FromString (decimal64 *result, const char *string,
130
                      decContext *set)
131
{
132
  decContext dc;                /* work */
133
  decNumber dn;                 /* .. */
134
 
135
  decContextDefault (&dc, DEC_INIT_DECIMAL64);  /* no traps, please */
136
  dc.round = set->round;        /* use supplied rounding */
137
 
138
  decNumberFromString (&dn, string, &dc);       /* will round if needed */
139
  decimal64FromNumber (result, &dn, &dc);
140
  if (dc.status != 0)
141
    {                           /* something happened */
142
      decContextSetStatus (set, dc.status);     /* .. pass it on */
143
    }
144
  return result;
145
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.