/* Packed decimal conversion module for the decNumber C Library.
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
Contributed by IBM Corporation. Author Mike Cowlishaw.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 2, or (at your option) any later
+ Software Foundation; either version 3, or (at your option) any later
version.
- In addition to the permissions in the GNU General Public License,
- the Free Software Foundation gives you unlimited permission to link
- the compiled version of this file into combinations with other
- programs, and to distribute those combinations without any
- restriction coming from the use of this file. (The General Public
- License restrictions do apply in other respects; for example, they
- cover modification of the file, and distribution when not linked
- into a combine executable.)
-
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
- You should have received a copy of the GNU General Public License
- along with GCC; see the file COPYING. If not, write to the Free
- Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
/* ------------------------------------------------------------------ */
/* Packed Decimal conversion module */
/* ------------------------------------------------------------------ */
-/* This module comprises the routines for Packed Decimal format */
+/* This module comprises the routines for Packed Decimal format */
/* numbers. Conversions are supplied to and from decNumber, which in */
/* turn supports: */
/* conversions to and from string */
/* arithmetic routines */
-/* utilities. */
+/* utilities. */
/* Conversions from decNumber to and from densely packed decimal */
/* formats are provided by the decimal32 through decimal128 modules. */
/* ------------------------------------------------------------------ */
/* */
/* bcd is the BCD bytes */
/* length is the length of the BCD array */
-/* scale is the scale result */
-/* dn is the decNumber */
+/* scale is the scale result */
+/* dn is the decNumber */
/* returns bcd, or NULL if error */
/* */
/* The number is converted to a BCD packed decimal byte array, */
/* as necessary. */
/* */
/* If there is an error (that is, the decNumber has too many digits */
-/* to fit in length bytes, or it is a NaN or Infinity), NULL is */
+/* to fit in length bytes, or it is a NaN or Infinity), NULL is */
/* returned and the bcd and scale results are unchanged. Otherwise */
/* bcd is returned. */
/* ------------------------------------------------------------------ */
if (dn->digits>length*2-1 /* too long .. */
||(dn->bits & DECSPECIAL)) return NULL; /* .. or special -- hopeless */
- if (dn->bits&DECNEG) obyte=DECPMINUS; /* set the sign .. */
- else obyte=DECPPLUS;
- *scale=-dn->exponent; /* .. and scale */
+ if (dn->bits&DECNEG) obyte=DECPMINUS; /* set the sign .. */
+ else obyte=DECPPLUS;
+ *scale=-dn->exponent; /* .. and scale */
/* loop from lowest (rightmost) byte */
out=bcd+length-1; /* -> final byte */
/* bcd is the BCD bytes */
/* length is the length of the BCD array */
/* scale is the scale associated with the BCD integer */
-/* dn is the decNumber [with space for length*2 digits] */
+/* dn is the decNumber [with space for length*2 digits] */
/* returns dn, or NULL if error */
/* */
/* The BCD packed decimal byte array, together with an associated */
/* no error is possible unless the adjusted exponent is out of range, */
/* no sign nibble was found, or a sign nibble was found before the */
/* final nibble. In these error cases, NULL is returned and the */
-/* decNumber will be 0. */
+/* decNumber will be 0. */
/* ------------------------------------------------------------------ */
decNumber * decPackedToNumber(const uByte *bcd, Int length,
const Int *scale, decNumber *dn) {
const uByte *first; /* -> first non-zero byte */
uInt nib; /* work nibble */
Unit *up=dn->lsu; /* output pointer */
- Int digits; /* digits count */
+ Int digits; /* digits count */
Int cut=0; /* phase of output */
decNumberZero(dn); /* default result */
/* leave as 1] */
/* check the adjusted exponent; note that scale could be unbounded */
- dn->exponent=-*scale; /* set the exponent */
+ dn->exponent=-*scale; /* set the exponent */
if (*scale>=0) { /* usual case */
if ((dn->digits-*scale-1)<-DECNUMMAXE) { /* underflow */
decNumberZero(dn);