Mercurial > hg > CbC > CbC_gcc
comparison libdecnumber/dpd/decimal32.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
22 a copy of the GCC Runtime Library Exception along with this program; | 22 a copy of the GCC Runtime Library Exception along with this program; |
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | 23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
24 <http://www.gnu.org/licenses/>. */ | 24 <http://www.gnu.org/licenses/>. */ |
25 | 25 |
26 /* ------------------------------------------------------------------ */ | 26 /* ------------------------------------------------------------------ */ |
27 /* Decimal 32-bit format module */ | 27 /* Decimal 32-bit format module */ |
28 /* ------------------------------------------------------------------ */ | 28 /* ------------------------------------------------------------------ */ |
29 /* This module comprises the routines for decimal32 format numbers. */ | 29 /* This module comprises the routines for decimal32 format numbers. */ |
30 /* Conversions are supplied to and from decNumber and String. */ | 30 /* Conversions are supplied to and from decNumber and String. */ |
31 /* */ | 31 /* */ |
32 /* This is used when decNumber provides operations, either for all */ | 32 /* This is used when decNumber provides operations, either for all */ |
35 /* Error handling is the same as decNumber (qv.). */ | 35 /* Error handling is the same as decNumber (qv.). */ |
36 /* ------------------------------------------------------------------ */ | 36 /* ------------------------------------------------------------------ */ |
37 #include <string.h> /* [for memset/memcpy] */ | 37 #include <string.h> /* [for memset/memcpy] */ |
38 #include <stdio.h> /* [for printf] */ | 38 #include <stdio.h> /* [for printf] */ |
39 | 39 |
40 #include "dconfig.h" /* GCC definitions */ | 40 #include "dconfig.h" /* GCC definitions */ |
41 #define DECNUMDIGITS 7 /* make decNumbers with space for 7 */ | 41 #define DECNUMDIGITS 7 /* make decNumbers with space for 7 */ |
42 #include "decNumber.h" /* base number library */ | 42 #include "decNumber.h" /* base number library */ |
43 #include "decNumberLocal.h" /* decNumber local types, etc. */ | 43 #include "decNumberLocal.h" /* decNumber local types, etc. */ |
44 #include "decimal32.h" /* our primary include */ | 44 #include "decimal32.h" /* our primary include */ |
45 | 45 |
46 /* Utility tables and routines [in decimal64.c] */ | 46 /* Utility tables and routines [in decimal64.c] */ |
62 #define DEC_clear(d) memset(d, 0, sizeof(*d)) | 62 #define DEC_clear(d) memset(d, 0, sizeof(*d)) |
63 | 63 |
64 /* ------------------------------------------------------------------ */ | 64 /* ------------------------------------------------------------------ */ |
65 /* decimal32FromNumber -- convert decNumber to decimal32 */ | 65 /* decimal32FromNumber -- convert decNumber to decimal32 */ |
66 /* */ | 66 /* */ |
67 /* ds is the target decimal32 */ | 67 /* ds is the target decimal32 */ |
68 /* dn is the source number (assumed valid) */ | 68 /* dn is the source number (assumed valid) */ |
69 /* set is the context, used only for reporting errors */ | 69 /* set is the context, used only for reporting errors */ |
70 /* */ | 70 /* */ |
71 /* The set argument is used only for status reporting and for the */ | 71 /* The set argument is used only for status reporting and for the */ |
72 /* rounding mode (used if the coefficient is more than DECIMAL32_Pmax */ | 72 /* rounding mode (used if the coefficient is more than DECIMAL32_Pmax */ |
73 /* digits or an overflow is detected). If the exponent is out of the */ | 73 /* digits or an overflow is detected). If the exponent is out of the */ |
74 /* valid range then Overflow or Underflow will be raised. */ | 74 /* valid range then Overflow or Underflow will be raised. */ |
82 decContext *set) { | 82 decContext *set) { |
83 uInt status=0; /* status accumulator */ | 83 uInt status=0; /* status accumulator */ |
84 Int ae; /* adjusted exponent */ | 84 Int ae; /* adjusted exponent */ |
85 decNumber dw; /* work */ | 85 decNumber dw; /* work */ |
86 decContext dc; /* .. */ | 86 decContext dc; /* .. */ |
87 uInt *pu; /* .. */ | |
88 uInt comb, exp; /* .. */ | 87 uInt comb, exp; /* .. */ |
88 uInt uiwork; /* for macros */ | |
89 uInt targ=0; /* target 32-bit */ | 89 uInt targ=0; /* target 32-bit */ |
90 | 90 |
91 /* If the number has too many digits, or the exponent could be */ | 91 /* If the number has too many digits, or the exponent could be */ |
92 /* out of range then reduce the number under the appropriate */ | 92 /* out of range then reduce the number under the appropriate */ |
93 /* constraints. This could push the number to Infinity or zero, */ | 93 /* constraints. This could push the number to Infinity or zero, */ |
94 /* so this check and rounding must be done before generating the */ | 94 /* so this check and rounding must be done before generating the */ |
95 /* decimal32] */ | 95 /* decimal32] */ |
96 ae=dn->exponent+dn->digits-1; /* [0 if special] */ | 96 ae=dn->exponent+dn->digits-1; /* [0 if special] */ |
97 if (dn->digits>DECIMAL32_Pmax /* too many digits */ | 97 if (dn->digits>DECIMAL32_Pmax /* too many digits */ |
98 || ae>DECIMAL32_Emax /* likely overflow */ | 98 || ae>DECIMAL32_Emax /* likely overflow */ |
99 || ae<DECIMAL32_Emin) { /* likely underflow */ | 99 || ae<DECIMAL32_Emin) { /* likely underflow */ |
100 decContextDefault(&dc, DEC_INIT_DECIMAL32); /* [no traps] */ | 100 decContextDefault(&dc, DEC_INIT_DECIMAL32); /* [no traps] */ |
101 dc.round=set->round; /* use supplied rounding */ | 101 dc.round=set->round; /* use supplied rounding */ |
102 decNumberPlus(&dw, dn, &dc); /* (round and check) */ | 102 decNumberPlus(&dw, dn, &dc); /* (round and check) */ |
103 /* [this changes -0 to 0, so enforce the sign...] */ | 103 /* [this changes -0 to 0, so enforce the sign...] */ |
107 } /* maybe out of range */ | 107 } /* maybe out of range */ |
108 | 108 |
109 if (dn->bits&DECSPECIAL) { /* a special value */ | 109 if (dn->bits&DECSPECIAL) { /* a special value */ |
110 if (dn->bits&DECINF) targ=DECIMAL_Inf<<24; | 110 if (dn->bits&DECINF) targ=DECIMAL_Inf<<24; |
111 else { /* sNaN or qNaN */ | 111 else { /* sNaN or qNaN */ |
112 if ((*dn->lsu!=0 || dn->digits>1) /* non-zero coefficient */ | 112 if ((*dn->lsu!=0 || dn->digits>1) /* non-zero coefficient */ |
113 && (dn->digits<DECIMAL32_Pmax)) { /* coefficient fits */ | 113 && (dn->digits<DECIMAL32_Pmax)) { /* coefficient fits */ |
114 decDigitsToDPD(dn, &targ, 0); | 114 decDigitsToDPD(dn, &targ, 0); |
115 } | 115 } |
116 if (dn->bits&DECNAN) targ|=DECIMAL_NaN<<24; | 116 if (dn->bits&DECNAN) targ|=DECIMAL_NaN<<24; |
117 else targ|=DECIMAL_sNaN<<24; | 117 else targ|=DECIMAL_sNaN<<24; |
133 } | 133 } |
134 } | 134 } |
135 comb=(exp>>3) & 0x18; /* msd=0, exp top 2 bits .. */ | 135 comb=(exp>>3) & 0x18; /* msd=0, exp top 2 bits .. */ |
136 } | 136 } |
137 else { /* non-zero finite number */ | 137 else { /* non-zero finite number */ |
138 uInt msd; /* work */ | 138 uInt msd; /* work */ |
139 Int pad=0; /* coefficient pad digits */ | 139 Int pad=0; /* coefficient pad digits */ |
140 | 140 |
141 /* the dn is known to fit, but it may need to be padded */ | 141 /* the dn is known to fit, but it may need to be padded */ |
142 exp=(uInt)(dn->exponent+DECIMAL32_Bias); /* bias exponent */ | 142 exp=(uInt)(dn->exponent+DECIMAL32_Bias); /* bias exponent */ |
143 if (exp>DECIMAL32_Ehigh) { /* fold-down case */ | 143 if (exp>DECIMAL32_Ehigh) { /* fold-down case */ |
168 } /* finite */ | 168 } /* finite */ |
169 | 169 |
170 if (dn->bits&DECNEG) targ|=0x80000000; /* add sign bit */ | 170 if (dn->bits&DECNEG) targ|=0x80000000; /* add sign bit */ |
171 | 171 |
172 /* now write to storage; this is endian */ | 172 /* now write to storage; this is endian */ |
173 pu=(uInt *)d32->bytes; /* overlay */ | 173 UBFROMUI(d32->bytes, targ); /* directly store the int */ |
174 *pu=targ; /* directly store the int */ | |
175 | 174 |
176 if (status!=0) decContextSetStatus(set, status); /* pass on status */ | 175 if (status!=0) decContextSetStatus(set, status); /* pass on status */ |
177 /* decimal32Show(d32); */ | 176 /* decimal32Show(d32); */ |
178 return d32; | 177 return d32; |
179 } /* decimal32FromNumber */ | 178 } /* decimal32FromNumber */ |
187 decNumber * decimal32ToNumber(const decimal32 *d32, decNumber *dn) { | 186 decNumber * decimal32ToNumber(const decimal32 *d32, decNumber *dn) { |
188 uInt msd; /* coefficient MSD */ | 187 uInt msd; /* coefficient MSD */ |
189 uInt exp; /* exponent top two bits */ | 188 uInt exp; /* exponent top two bits */ |
190 uInt comb; /* combination field */ | 189 uInt comb; /* combination field */ |
191 uInt sour; /* source 32-bit */ | 190 uInt sour; /* source 32-bit */ |
192 const uInt *pu; /* work */ | 191 uInt uiwork; /* for macros */ |
193 | 192 |
194 /* load source from storage; this is endian */ | 193 /* load source from storage; this is endian */ |
195 pu=(const uInt *)d32->bytes; /* overlay */ | 194 sour=UBTOUI(d32->bytes); /* directly load the int */ |
196 sour=*pu; /* directly load the int */ | 195 |
197 | 196 comb=(sour>>26)&0x1f; /* combination field */ |
198 comb=(sour>>26)&0x1f; /* combination field */ | |
199 | 197 |
200 decNumberZero(dn); /* clean number */ | 198 decNumberZero(dn); /* clean number */ |
201 if (sour&0x80000000) dn->bits=DECNEG; /* set sign if negative */ | 199 if (sour&0x80000000) dn->bits=DECNEG; /* set sign if negative */ |
202 | 200 |
203 msd=COMBMSD[comb]; /* decode the combination field */ | 201 msd=COMBMSD[comb]; /* decode the combination field */ |
204 exp=COMBEXP[comb]; /* .. */ | 202 exp=COMBEXP[comb]; /* .. */ |
205 | 203 |
206 if (exp==3) { /* is a special */ | 204 if (exp==3) { /* is a special */ |
207 if (msd==0) { | 205 if (msd==0) { |
208 dn->bits|=DECINF; | 206 dn->bits|=DECINF; |
209 return dn; /* no coefficient needed */ | 207 return dn; /* no coefficient needed */ |
210 } | 208 } |
211 else if (sour&0x02000000) dn->bits|=DECSNAN; | 209 else if (sour&0x02000000) dn->bits|=DECSNAN; |
222 sour|=msd<<20; /* prefix to coefficient */ | 220 sour|=msd<<20; /* prefix to coefficient */ |
223 decDigitsFromDPD(dn, &sour, 3); /* process 3 declets */ | 221 decDigitsFromDPD(dn, &sour, 3); /* process 3 declets */ |
224 return dn; | 222 return dn; |
225 } | 223 } |
226 /* msd=0 */ | 224 /* msd=0 */ |
227 if (!sour) return dn; /* easy: coefficient is 0 */ | 225 if (!sour) return dn; /* easy: coefficient is 0 */ |
228 if (sour&0x000ffc00) /* need 2 declets? */ | 226 if (sour&0x000ffc00) /* need 2 declets? */ |
229 decDigitsFromDPD(dn, &sour, 2); /* process 2 declets */ | 227 decDigitsFromDPD(dn, &sour, 2); /* process 2 declets */ |
230 else | 228 else |
231 decDigitsFromDPD(dn, &sour, 1); /* process 1 declet */ | 229 decDigitsFromDPD(dn, &sour, 1); /* process 1 declet */ |
232 return dn; | 230 return dn; |
233 } /* decimal32ToNumber */ | 231 } /* decimal32ToNumber */ |
234 | 232 |
235 /* ------------------------------------------------------------------ */ | 233 /* ------------------------------------------------------------------ */ |
236 /* to-scientific-string -- conversion to numeric string */ | 234 /* to-scientific-string -- conversion to numeric string */ |
237 /* to-engineering-string -- conversion to numeric string */ | 235 /* to-engineering-string -- conversion to numeric string */ |
238 /* */ | 236 /* */ |
239 /* decimal32ToString(d32, string); */ | 237 /* decimal32ToString(d32, string); */ |
240 /* decimal32ToEngString(d32, string); */ | 238 /* decimal32ToEngString(d32, string); */ |
241 /* */ | 239 /* */ |
242 /* d32 is the decimal32 format number to convert */ | 240 /* d32 is the decimal32 format number to convert */ |
243 /* string is the string where the result will be laid out */ | 241 /* string is the string where the result will be laid out */ |
244 /* */ | 242 /* */ |
245 /* string must be at least 24 characters */ | 243 /* string must be at least 24 characters */ |
246 /* */ | 244 /* */ |
247 /* No error is possible, and no status can be set. */ | 245 /* No error is possible, and no status can be set. */ |
248 /* ------------------------------------------------------------------ */ | 246 /* ------------------------------------------------------------------ */ |
249 char * decimal32ToEngString(const decimal32 *d32, char *string){ | 247 char * decimal32ToEngString(const decimal32 *d32, char *string){ |
250 decNumber dn; /* work */ | 248 decNumber dn; /* work */ |
251 decimal32ToNumber(d32, &dn); | 249 decimal32ToNumber(d32, &dn); |
252 decNumberToEngString(&dn, string); | 250 decNumberToEngString(&dn, string); |
253 return string; | 251 return string; |
254 } /* decimal32ToEngString */ | 252 } /* decimal32ToEngString */ |
255 | 253 |
256 char * decimal32ToString(const decimal32 *d32, char *string){ | 254 char * decimal32ToString(const decimal32 *d32, char *string){ |
257 uInt msd; /* coefficient MSD */ | 255 uInt msd; /* coefficient MSD */ |
258 Int exp; /* exponent top two bits or full */ | 256 Int exp; /* exponent top two bits or full */ |
259 uInt comb; /* combination field */ | 257 uInt comb; /* combination field */ |
260 char *cstart; /* coefficient start */ | 258 char *cstart; /* coefficient start */ |
261 char *c; /* output pointer in string */ | 259 char *c; /* output pointer in string */ |
262 const uInt *pu; /* work */ | 260 const uByte *u; /* work */ |
263 const uByte *u; /* .. */ | |
264 char *s, *t; /* .. (source, target) */ | 261 char *s, *t; /* .. (source, target) */ |
265 Int dpd; /* .. */ | 262 Int dpd; /* .. */ |
266 Int pre, e; /* .. */ | 263 Int pre, e; /* .. */ |
264 uInt uiwork; /* for macros */ | |
267 uInt sour; /* source 32-bit */ | 265 uInt sour; /* source 32-bit */ |
268 | 266 |
269 /* load source from storage; this is endian */ | 267 /* load source from storage; this is endian */ |
270 pu=(const uInt *)d32->bytes; /* overlay */ | 268 sour=UBTOUI(d32->bytes); /* directly load the int */ |
271 sour=*pu; /* directly load the int */ | |
272 | 269 |
273 c=string; /* where result will go */ | 270 c=string; /* where result will go */ |
274 if (((Int)sour)<0) *c++='-'; /* handle sign */ | 271 if (((Int)sour)<0) *c++='-'; /* handle sign */ |
275 | 272 |
276 comb=(sour>>26)&0x1f; /* combination field */ | 273 comb=(sour>>26)&0x1f; /* combination field */ |
277 msd=COMBMSD[comb]; /* decode the combination field */ | 274 msd=COMBMSD[comb]; /* decode the combination field */ |
278 exp=COMBEXP[comb]; /* .. */ | 275 exp=COMBEXP[comb]; /* .. */ |
279 | 276 |
280 if (exp==3) { | 277 if (exp==3) { |
281 if (msd==0) { /* infinity */ | 278 if (msd==0) { /* infinity */ |
282 strcpy(c, "Inf"); | 279 strcpy(c, "Inf"); |
283 strcpy(c+3, "inity"); | 280 strcpy(c+3, "inity"); |
284 return string; /* easy */ | 281 return string; /* easy */ |
285 } | 282 } |
286 if (sour&0x02000000) *c++='s'; /* sNaN */ | 283 if (sour&0x02000000) *c++='s'; /* sNaN */ |
287 strcpy(c, "NaN"); /* complete word */ | 284 strcpy(c, "NaN"); /* complete word */ |
302 /* has length 0). This allows us to left-align the first declet */ | 299 /* has length 0). This allows us to left-align the first declet */ |
303 /* with non-zero content, then remaining ones are full 3-char */ | 300 /* with non-zero content, then remaining ones are full 3-char */ |
304 /* length. We use fixed-length memcpys because variable-length */ | 301 /* length. We use fixed-length memcpys because variable-length */ |
305 /* causes a subroutine call in GCC. (These are length 4 for speed */ | 302 /* causes a subroutine call in GCC. (These are length 4 for speed */ |
306 /* and are safe because the array has an extra terminator byte.) */ | 303 /* and are safe because the array has an extra terminator byte.) */ |
307 #define dpd2char u=&BIN2CHAR[DPD2BIN[dpd]*4]; \ | 304 #define dpd2char u=&BIN2CHAR[DPD2BIN[dpd]*4]; \ |
308 if (c!=cstart) {memcpy(c, u+1, 4); c+=3;} \ | 305 if (c!=cstart) {memcpy(c, u+1, 4); c+=3;} \ |
309 else if (*u) {memcpy(c, u+4-*u, 4); c+=*u;} | 306 else if (*u) {memcpy(c, u+4-*u, 4); c+=*u;} |
310 | 307 |
311 dpd=(sour>>10)&0x3ff; /* declet 1 */ | 308 dpd=(sour>>10)&0x3ff; /* declet 1 */ |
312 dpd2char; | 309 dpd2char; |
313 dpd=(sour)&0x3ff; /* declet 2 */ | 310 dpd=(sour)&0x3ff; /* declet 2 */ |
314 dpd2char; | 311 dpd2char; |
315 | 312 |
316 if (c==cstart) *c++='0'; /* all zeros -- make 0 */ | 313 if (c==cstart) *c++='0'; /* all zeros -- make 0 */ |
317 | 314 |
318 if (exp==0) { /* integer or NaN case -- easy */ | 315 if (exp==0) { /* integer or NaN case -- easy */ |
319 *c='\0'; /* terminate */ | 316 *c='\0'; /* terminate */ |
320 return string; | 317 return string; |
321 } | 318 } |
322 | 319 |
323 /* non-0 exponent */ | 320 /* non-0 exponent */ |
341 } | 338 } |
342 | 339 |
343 /* finally add the E-part, if needed; it will never be 0, and has */ | 340 /* finally add the E-part, if needed; it will never be 0, and has */ |
344 /* a maximum length of 3 digits (E-101 case) */ | 341 /* a maximum length of 3 digits (E-101 case) */ |
345 if (e!=0) { | 342 if (e!=0) { |
346 *c++='E'; /* starts with E */ | 343 *c++='E'; /* starts with E */ |
347 *c++='+'; /* assume positive */ | 344 *c++='+'; /* assume positive */ |
348 if (e<0) { | 345 if (e<0) { |
349 *(c-1)='-'; /* oops, need '-' */ | 346 *(c-1)='-'; /* oops, need '-' */ |
350 e=-e; /* uInt, please */ | 347 e=-e; /* uInt, please */ |
351 } | 348 } |
352 u=&BIN2CHAR[e*4]; /* -> length byte */ | 349 u=&BIN2CHAR[e*4]; /* -> length byte */ |
353 memcpy(c, u+4-*u, 4); /* copy fixed 4 characters [is safe] */ | 350 memcpy(c, u+4-*u, 4); /* copy fixed 4 characters [is safe] */ |
354 c+=*u; /* bump pointer appropriately */ | 351 c+=*u; /* bump pointer appropriately */ |
355 } | 352 } |
356 *c='\0'; /* add terminator */ | 353 *c='\0'; /* add terminator */ |
357 /*printf("res %s\n", string); */ | 354 /*printf("res %s\n", string); */ |
377 /* */ | 374 /* */ |
378 /* result is the decimal32 format number which gets the result of */ | 375 /* result is the decimal32 format number which gets the result of */ |
379 /* the conversion */ | 376 /* the conversion */ |
380 /* *string is the character string which should contain a valid */ | 377 /* *string is the character string which should contain a valid */ |
381 /* number (which may be a special value) */ | 378 /* number (which may be a special value) */ |
382 /* set is the context */ | 379 /* set is the context */ |
383 /* */ | 380 /* */ |
384 /* The context is supplied to this routine is used for error handling */ | 381 /* The context is supplied to this routine is used for error handling */ |
385 /* (setting of status and traps) and for the rounding mode, only. */ | 382 /* (setting of status and traps) and for the rounding mode, only. */ |
386 /* If an error occurs, the result will be a valid decimal32 NaN. */ | 383 /* If an error occurs, the result will be a valid decimal32 NaN. */ |
387 /* ------------------------------------------------------------------ */ | 384 /* ------------------------------------------------------------------ */ |
388 decimal32 * decimal32FromString(decimal32 *result, const char *string, | 385 decimal32 * decimal32FromString(decimal32 *result, const char *string, |
389 decContext *set) { | 386 decContext *set) { |
390 decContext dc; /* work */ | 387 decContext dc; /* work */ |
391 decNumber dn; /* .. */ | 388 decNumber dn; /* .. */ |
392 | 389 |
393 decContextDefault(&dc, DEC_INIT_DECIMAL32); /* no traps, please */ | 390 decContextDefault(&dc, DEC_INIT_DECIMAL32); /* no traps, please */ |
394 dc.round=set->round; /* use supplied rounding */ | 391 dc.round=set->round; /* use supplied rounding */ |
395 | 392 |
396 decNumberFromString(&dn, string, &dc); /* will round if needed */ | 393 decNumberFromString(&dn, string, &dc); /* will round if needed */ |
402 } /* decimal32FromString */ | 399 } /* decimal32FromString */ |
403 | 400 |
404 /* ------------------------------------------------------------------ */ | 401 /* ------------------------------------------------------------------ */ |
405 /* decimal32IsCanonical -- test whether encoding is canonical */ | 402 /* decimal32IsCanonical -- test whether encoding is canonical */ |
406 /* d32 is the source decimal32 */ | 403 /* d32 is the source decimal32 */ |
407 /* returns 1 if the encoding of d32 is canonical, 0 otherwise */ | 404 /* returns 1 if the encoding of d32 is canonical, 0 otherwise */ |
408 /* No error is possible. */ | 405 /* No error is possible. */ |
409 /* ------------------------------------------------------------------ */ | 406 /* ------------------------------------------------------------------ */ |
410 uint32_t decimal32IsCanonical(const decimal32 *d32) { | 407 uInt decimal32IsCanonical(const decimal32 *d32) { |
411 decNumber dn; /* work */ | 408 decNumber dn; /* work */ |
412 decimal32 canon; /* .. */ | 409 decimal32 canon; /* .. */ |
413 decContext dc; /* .. */ | 410 decContext dc; /* .. */ |
414 decContextDefault(&dc, DEC_INIT_DECIMAL32); | 411 decContextDefault(&dc, DEC_INIT_DECIMAL32); |
415 decimal32ToNumber(d32, &dn); | 412 decimal32ToNumber(d32, &dn); |
416 decimal32FromNumber(&canon, &dn, &dc);/* canon will now be canonical */ | 413 decimal32FromNumber(&canon, &dn, &dc);/* canon will now be canonical */ |
423 /* result is the target (may be the same decimal32) */ | 420 /* result is the target (may be the same decimal32) */ |
424 /* returns result */ | 421 /* returns result */ |
425 /* No error is possible. */ | 422 /* No error is possible. */ |
426 /* ------------------------------------------------------------------ */ | 423 /* ------------------------------------------------------------------ */ |
427 decimal32 * decimal32Canonical(decimal32 *result, const decimal32 *d32) { | 424 decimal32 * decimal32Canonical(decimal32 *result, const decimal32 *d32) { |
428 decNumber dn; /* work */ | 425 decNumber dn; /* work */ |
429 decContext dc; /* .. */ | 426 decContext dc; /* .. */ |
430 decContextDefault(&dc, DEC_INIT_DECIMAL32); | 427 decContextDefault(&dc, DEC_INIT_DECIMAL32); |
431 decimal32ToNumber(d32, &dn); | 428 decimal32ToNumber(d32, &dn); |
432 decimal32FromNumber(result, &dn, &dc);/* result will now be canonical */ | 429 decimal32FromNumber(result, &dn, &dc);/* result will now be canonical */ |
433 return result; | 430 return result; |
453 | 450 |
454 /* Set exponent continuation [does not apply bias] */ | 451 /* Set exponent continuation [does not apply bias] */ |
455 /* This assumes range has been checked and exponent previously 0; */ | 452 /* This assumes range has been checked and exponent previously 0; */ |
456 /* type of exponent must be unsigned */ | 453 /* type of exponent must be unsigned */ |
457 #define decimal32SetExpCon(d, e) { \ | 454 #define decimal32SetExpCon(d, e) { \ |
458 (d)->bytes[0]|=(uint8_t)((e)>>4); \ | 455 (d)->bytes[0]|=(uByte)((e)>>4); \ |
459 (d)->bytes[1]|=(uint8_t)(((e)&0x0F)<<4);} | 456 (d)->bytes[1]|=(uByte)(((e)&0x0F)<<4);} |
460 | 457 |
461 /* ------------------------------------------------------------------ */ | 458 /* ------------------------------------------------------------------ */ |
462 /* decimal32Show -- display a decimal32 in hexadecimal [debug aid] */ | 459 /* decimal32Show -- display a decimal32 in hexadecimal [debug aid] */ |
463 /* d32 -- the number to show */ | 460 /* d32 -- the number to show */ |
464 /* ------------------------------------------------------------------ */ | 461 /* ------------------------------------------------------------------ */ |