Commit f988ec96 by Ben Elliston Committed by Ben Elliston

decNumber.c, [...]: Upgrade to decNumber 3.61.

	* decNumber.c, decNumber.h, decNumberLocal.h, decDouble.c,
	decDouble.h, decSingle.c, decContext.c, decSingle.h, decPacked.c,
	decCommon.c, decContext.h, decQuad.c, decPacked.h, decQuad.h,
	decDPD.h, decBasic.c: Upgrade to decNumber 3.61.
	* dpd/decimal128.h, dpd/decimal32.c, dpd/decimal32.h,
	dpd/decimal64.c, dpd/decimal128.c, dpd/decimal64.h: Likewise.

From-SVN: r145222
parent 7cdc1972
2009-03-29 Ben Elliston <bje@au.ibm.com>
* decNumber.c, decNumber.h, decNumberLocal.h, decDouble.c,
decDouble.h, decSingle.c, decContext.c, decSingle.h, decPacked.c,
decCommon.c, decContext.h, decQuad.c, decPacked.h, decQuad.h,
decDPD.h, decBasic.c: Upgrade to decNumber 3.61.
* dpd/decimal128.h, dpd/decimal32.c, dpd/decimal32.h,
dpd/decimal64.c, dpd/decimal128.c, dpd/decimal64.h: Likewise.
2009-02-10 Joseph Myers <joseph@codesourcery.com> 2009-02-10 Joseph Myers <joseph@codesourcery.com>
* Makefile.in (clean): Don't remove makedepend$(EXEEXT). * Makefile.in (clean): Don't remove makedepend$(EXEEXT).
......
...@@ -41,12 +41,10 @@ ...@@ -41,12 +41,10 @@
#include "decContext.h" /* context and base types */ #include "decContext.h" /* context and base types */
#include "decNumberLocal.h" /* decNumber local types, etc. */ #include "decNumberLocal.h" /* decNumber local types, etc. */
#if DECCHECK
/* compile-time endian tester [assumes sizeof(Int)>1] */ /* compile-time endian tester [assumes sizeof(Int)>1] */
static const Int mfcone=1; /* constant 1 */ static const Int mfcone=1; /* constant 1 */
static const Flag *mfctop=(Flag *)&mfcone; /* -> top byte */ static const Flag *mfctop=(const Flag *)&mfcone; /* -> top byte */
#define LITEND *mfctop /* named flag; 1=little-endian */ #define LITEND *mfctop /* named flag; 1=little-endian */
#endif
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* round-for-reround digits */ /* round-for-reround digits */
...@@ -80,9 +78,9 @@ decContext *decContextClearStatus(decContext *context, uInt mask) { ...@@ -80,9 +78,9 @@ decContext *decContextClearStatus(decContext *context, uInt mask) {
/* context is the structure to be initialized */ /* context is the structure to be initialized */
/* kind selects the required set of default values, one of: */ /* kind selects the required set of default values, one of: */
/* DEC_INIT_BASE -- select ANSI X3-274 defaults */ /* DEC_INIT_BASE -- select ANSI X3-274 defaults */
/* DEC_INIT_DECIMAL32 -- select IEEE 754r defaults, 32-bit */ /* DEC_INIT_DECIMAL32 -- select IEEE 754 defaults, 32-bit */
/* DEC_INIT_DECIMAL64 -- select IEEE 754r defaults, 64-bit */ /* DEC_INIT_DECIMAL64 -- select IEEE 754 defaults, 64-bit */
/* DEC_INIT_DECIMAL128 -- select IEEE 754r defaults, 128-bit */ /* DEC_INIT_DECIMAL128 -- select IEEE 754 defaults, 128-bit */
/* For any other value a valid context is returned, but with */ /* For any other value a valid context is returned, but with */
/* Invalid_operation set in the status field. */ /* Invalid_operation set in the status field. */
/* returns a context structure with the appropriate initial values. */ /* returns a context structure with the appropriate initial values. */
...@@ -142,15 +140,6 @@ decContext * decContextDefault(decContext *context, Int kind) { ...@@ -142,15 +140,6 @@ decContext * decContextDefault(decContext *context, Int kind) {
decContextSetStatus(context, DEC_Invalid_operation); /* trap */ decContextSetStatus(context, DEC_Invalid_operation); /* trap */
} }
#if DECCHECK
if (LITEND!=DECLITEND) {
const char *adj;
if (LITEND) adj="little";
else adj="big";
printf("Warning: DECLITEND is set to %d, but this computer appears to be %s-endian\n",
DECLITEND, adj);
}
#endif
return context;} /* decContextDefault */ return context;} /* decContextDefault */
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
...@@ -390,6 +379,36 @@ const char *decContextStatusToString(const decContext *context) { ...@@ -390,6 +379,36 @@ const char *decContextStatusToString(const decContext *context) {
} /* decContextStatusToString */ } /* decContextStatusToString */
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* decContextTestEndian -- test whether DECLITEND is set correctly */
/* */
/* quiet is 1 to suppress message; 0 otherwise */
/* returns 0 if DECLITEND is correct */
/* 1 if DECLITEND is incorrect and should be 1 */
/* -1 if DECLITEND is incorrect and should be 0 */
/* */
/* A message is displayed if the return value is not 0 and quiet==0. */
/* */
/* No error is possible. */
/* ------------------------------------------------------------------ */
Int decContextTestEndian(Flag quiet) {
Int res=0; /* optimist */
uInt dle=(uInt)DECLITEND; /* unsign */
if (dle>1) dle=1; /* ensure 0 or 1 */
if (LITEND!=DECLITEND) {
const char *adj;
if (!quiet) {
if (LITEND) adj="little";
else adj="big";
printf("Warning: DECLITEND is set to %d, but this computer appears to be %s-endian\n",
DECLITEND, adj);
}
res=(Int)LITEND-dle;
}
return res;
} /* decContextTestEndian */
/* ------------------------------------------------------------------ */
/* decContextTestSavedStatus -- test bits in saved status */ /* decContextTestSavedStatus -- test bits in saved status */
/* */ /* */
/* oldstatus is the status word to be tested */ /* oldstatus is the status word to be tested */
......
...@@ -56,15 +56,21 @@ ...@@ -56,15 +56,21 @@
#define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */ #define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */
#define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */ #define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */
#include "gstdint.h" /* C99 standard integers */ #if !defined(int32_t)
#include <stdint.h> /* C99 standard integers */
#endif
#include <stdio.h> /* for printf, etc. */ #include <stdio.h> /* for printf, etc. */
#include <signal.h> /* for traps */ #include <signal.h> /* for traps */
/* Extended flags setting -- set this to 0 to use only IEEE flags */ /* Extended flags setting -- set this to 0 to use only IEEE flags */
#if !defined(DECEXTFLAG)
#define DECEXTFLAG 1 /* 1=enable extended flags */ #define DECEXTFLAG 1 /* 1=enable extended flags */
#endif
/* Conditional code flag -- set this to 0 for best performance */ /* Conditional code flag -- set this to 0 for best performance */
#if !defined(DECSUBSET)
#define DECSUBSET 0 /* 1=enable subset arithmetic */ #define DECSUBSET 0 /* 1=enable subset arithmetic */
#endif
/* Context for operations, with associated constants */ /* Context for operations, with associated constants */
enum rounding { enum rounding {
...@@ -102,9 +108,9 @@ ...@@ -102,9 +108,9 @@
#define DEC_MIN_EMIN -999999999 #define DEC_MIN_EMIN -999999999
#define DEC_MAX_MATH 999999 /* max emax, etc., for math funcs. */ #define DEC_MAX_MATH 999999 /* max emax, etc., for math funcs. */
/* Classifications for decimal numbers, aligned with 754r (note */ /* Classifications for decimal numbers, aligned with 754 (note that */
/* that 'normal' and 'subnormal' are meaningful only with a */ /* 'normal' and 'subnormal' are meaningful only with a decContext */
/* decContext or a fixed size format). */ /* or a fixed size format). */
enum decClass { enum decClass {
DEC_CLASS_SNAN, DEC_CLASS_SNAN,
DEC_CLASS_QNAN, DEC_CLASS_QNAN,
...@@ -170,30 +176,30 @@ ...@@ -170,30 +176,30 @@
#define DEC_Underflow 0x00000004 #define DEC_Underflow 0x00000004
#endif #endif
/* IEEE 854 groupings for the flags */ /* IEEE 754 groupings for the flags */
/* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal */ /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal */
/* are not in IEEE 854] */ /* are not in IEEE 754] */
#define DEC_IEEE_854_Division_by_zero (DEC_Division_by_zero) #define DEC_IEEE_754_Division_by_zero (DEC_Division_by_zero)
#if DECSUBSET #if DECSUBSET
#define DEC_IEEE_854_Inexact (DEC_Inexact | DEC_Lost_digits) #define DEC_IEEE_754_Inexact (DEC_Inexact | DEC_Lost_digits)
#else #else
#define DEC_IEEE_854_Inexact (DEC_Inexact) #define DEC_IEEE_754_Inexact (DEC_Inexact)
#endif #endif
#define DEC_IEEE_854_Invalid_operation (DEC_Conversion_syntax | \ #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax | \
DEC_Division_impossible | \ DEC_Division_impossible | \
DEC_Division_undefined | \ DEC_Division_undefined | \
DEC_Insufficient_storage | \ DEC_Insufficient_storage | \
DEC_Invalid_context | \ DEC_Invalid_context | \
DEC_Invalid_operation) DEC_Invalid_operation)
#define DEC_IEEE_854_Overflow (DEC_Overflow) #define DEC_IEEE_754_Overflow (DEC_Overflow)
#define DEC_IEEE_854_Underflow (DEC_Underflow) #define DEC_IEEE_754_Underflow (DEC_Underflow)
/* flags which are normally errors (result is qNaN, infinite, or 0) */ /* flags which are normally errors (result is qNaN, infinite, or 0) */
#define DEC_Errors (DEC_IEEE_854_Division_by_zero | \ #define DEC_Errors (DEC_IEEE_754_Division_by_zero | \
DEC_IEEE_854_Invalid_operation | \ DEC_IEEE_754_Invalid_operation | \
DEC_IEEE_854_Overflow | DEC_IEEE_854_Underflow) DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow)
/* flags which cause a result to become qNaN */ /* flags which cause a result to become qNaN */
#define DEC_NaNs DEC_IEEE_854_Invalid_operation #define DEC_NaNs DEC_IEEE_754_Invalid_operation
/* flags which are normally for information only (finite results) */ /* flags which are normally for information only (finite results) */
#if DECSUBSET #if DECSUBSET
...@@ -203,6 +209,13 @@ ...@@ -203,6 +209,13 @@
#define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact) #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
#endif #endif
/* IEEE 854 names (for compatibility with older decNumber versions) */
#define DEC_IEEE_854_Division_by_zero DEC_IEEE_754_Division_by_zero
#define DEC_IEEE_854_Inexact DEC_IEEE_754_Inexact
#define DEC_IEEE_854_Invalid_operation DEC_IEEE_754_Invalid_operation
#define DEC_IEEE_854_Overflow DEC_IEEE_754_Overflow
#define DEC_IEEE_854_Underflow DEC_IEEE_754_Underflow
/* Name strings for the exceptional conditions */ /* Name strings for the exceptional conditions */
#define DEC_Condition_CS "Conversion syntax" #define DEC_Condition_CS "Conversion syntax"
#define DEC_Condition_DZ "Division by zero" #define DEC_Condition_DZ "Division by zero"
...@@ -251,6 +264,7 @@ ...@@ -251,6 +264,7 @@
extern decContext * decContextSetStatusFromStringQuiet(decContext *, const char *); extern decContext * decContextSetStatusFromStringQuiet(decContext *, const char *);
extern decContext * decContextSetStatusQuiet(decContext *, uint32_t); extern decContext * decContextSetStatusQuiet(decContext *, uint32_t);
extern const char * decContextStatusToString(const decContext *); extern const char * decContextStatusToString(const decContext *);
extern int32_t decContextTestEndian(uint8_t);
extern uint32_t decContextTestSavedStatus(uint32_t, uint32_t); extern uint32_t decContextTestSavedStatus(uint32_t, uint32_t);
extern uint32_t decContextTestStatus(decContext *, uint32_t); extern uint32_t decContextTestStatus(decContext *, uint32_t);
extern decContext * decContextZeroStatus(decContext *); extern decContext * decContextZeroStatus(decContext *);
......
...@@ -30,10 +30,9 @@ ...@@ -30,10 +30,9 @@
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/* Binary Coded Decimal and Densely Packed Decimal conversion lookup tables */ /* Binary Coded Decimal and Densely Packed Decimal conversion lookup tables */
/* [Automatically generated -- do not edit. 2007.05.05] */ /* [Automatically generated -- do not edit. 2008.06.21] */
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */ /* For details, see DPDecimal.html on the General Decimal Arithmetic page. */
/* For details, see: http://www2.hursley.ibm.com/decimal/DPDecimal.html */
#include "decDPDSymbols.h" #include "decDPDSymbols.h"
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#define decFloatFromBCD decDoubleFromBCD #define decFloatFromBCD decDoubleFromBCD
#define decFloatFromInt32 decDoubleFromInt32 #define decFloatFromInt32 decDoubleFromInt32
#define decFloatFromPacked decDoubleFromPacked #define decFloatFromPacked decDoubleFromPacked
#define decFloatFromPackedChecked decDoubleFromPackedChecked
#define decFloatFromString decDoubleFromString #define decFloatFromString decDoubleFromString
#define decFloatFromUInt32 decDoubleFromUInt32 #define decFloatFromUInt32 decDoubleFromUInt32
#define decFloatFromWider decDoubleFromWider #define decFloatFromWider decDoubleFromWider
...@@ -145,10 +146,7 @@ ...@@ -145,10 +146,7 @@
#define decFloatSameQuantum decDoubleSameQuantum #define decFloatSameQuantum decDoubleSameQuantum
#define decFloatVersion decDoubleVersion #define decFloatVersion decDoubleVersion
#include "decNumberLocal.h" /* local includes (need DECPMAX) */ #include "decNumberLocal.h" /* local includes (need DECPMAX) */
#include "decCommon.c" /* non-arithmetic decFloat routines */ #include "decCommon.c" /* non-arithmetic decFloat routines */
#include "decBasic.c" /* basic formats routines */ #include "decBasic.c" /* basic formats routines */
/* Below here will move to shared file as completed */
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* decDouble.h -- Decimal 64-bit format module header */ /* decDouble.h -- Decimal 64-bit format module header */
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* Please see decFloats.h for an overview and documentation details. */
/* ------------------------------------------------------------------ */
#if !defined(DECDOUBLE) #if !defined(DECDOUBLE)
#define DECDOUBLE #define DECDOUBLE
...@@ -58,11 +56,14 @@ ...@@ -58,11 +56,14 @@
#include "decContext.h" #include "decContext.h"
#include "decQuad.h" #include "decQuad.h"
/* The decDouble decimal 64-bit type, accessible by various types */ /* The decDouble decimal 64-bit type, accessible by all sizes */
typedef union { typedef union {
uint8_t bytes[DECDOUBLE_Bytes]; /* fields: 1, 5, 8, 50 bits */ uint8_t bytes[DECDOUBLE_Bytes]; /* fields: 1, 5, 8, 50 bits */
uint16_t shorts[DECDOUBLE_Bytes/2]; uint16_t shorts[DECDOUBLE_Bytes/2];
uint32_t words[DECDOUBLE_Bytes/4]; uint32_t words[DECDOUBLE_Bytes/4];
#if DECUSE64
uint64_t longs[DECDOUBLE_Bytes/8];
#endif
} decDouble; } decDouble;
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
...@@ -75,6 +76,7 @@ ...@@ -75,6 +76,7 @@
extern decDouble * decDoubleFromBCD(decDouble *, int32_t, const uint8_t *, int32_t); extern decDouble * decDoubleFromBCD(decDouble *, int32_t, const uint8_t *, int32_t);
extern decDouble * decDoubleFromInt32(decDouble *, int32_t); extern decDouble * decDoubleFromInt32(decDouble *, int32_t);
extern decDouble * decDoubleFromPacked(decDouble *, int32_t, const uint8_t *); extern decDouble * decDoubleFromPacked(decDouble *, int32_t, const uint8_t *);
extern decDouble * decDoubleFromPackedChecked(decDouble *, int32_t, const uint8_t *);
extern decDouble * decDoubleFromString(decDouble *, const char *, decContext *); extern decDouble * decDoubleFromString(decDouble *, const char *, decContext *);
extern decDouble * decDoubleFromUInt32(decDouble *, uint32_t); extern decDouble * decDoubleFromUInt32(decDouble *, uint32_t);
extern decDouble * decDoubleFromWider(decDouble *, const decQuad *, decContext *); extern decDouble * decDoubleFromWider(decDouble *, const decQuad *, decContext *);
...@@ -160,7 +162,8 @@ ...@@ -160,7 +162,8 @@
/* decNumber conversions; these are implemented as macros so as not */ /* decNumber conversions; these are implemented as macros so as not */
/* to force a dependency on decimal64 and decNumber in decDouble. */ /* to force a dependency on decimal64 and decNumber in decDouble. */
/* decDoubleFromNumber returns a decimal64 * to avoid warnings. */
#define decDoubleToNumber(dq, dn) decimal64ToNumber((decimal64 *)(dq), dn) #define decDoubleToNumber(dq, dn) decimal64ToNumber((decimal64 *)(dq), dn)
#define decDoubleFromNumber(dq, dn, set) (decDouble *)decimal64FromNumber((decimal64 *)(dq), dn, set) #define decDoubleFromNumber(dq, dn, set) decimal64FromNumber((decimal64 *)(dq), dn, set)
#endif #endif
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#define decFloatFromBCD decQuadFromBCD #define decFloatFromBCD decQuadFromBCD
#define decFloatFromInt32 decQuadFromInt32 #define decFloatFromInt32 decQuadFromInt32
#define decFloatFromPacked decQuadFromPacked #define decFloatFromPacked decQuadFromPacked
#define decFloatFromPackedChecked decQuadFromPackedChecked
#define decFloatFromString decQuadFromString #define decFloatFromString decQuadFromString
#define decFloatFromUInt32 decQuadFromUInt32 #define decFloatFromUInt32 decQuadFromUInt32
#define decFloatFromWider decQuadFromWider #define decFloatFromWider decQuadFromWider
...@@ -139,7 +140,6 @@ ...@@ -139,7 +140,6 @@
#define decFloatSameQuantum decQuadSameQuantum #define decFloatSameQuantum decQuadSameQuantum
#define decFloatVersion decQuadVersion #define decFloatVersion decQuadVersion
#include "decNumberLocal.h" /* local includes (need DECPMAX) */ #include "decNumberLocal.h" /* local includes (need DECPMAX) */
#include "decCommon.c" /* non-arithmetic decFloat routines */ #include "decCommon.c" /* non-arithmetic decFloat routines */
#include "decBasic.c" /* basic formats routines */ #include "decBasic.c" /* basic formats routines */
......
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* decQuad.h -- Decimal 128-bit format module header */ /* decQuad.h -- Decimal 128-bit format module header */
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* Please see decFloats.h for an overview and documentation details. */
/* ------------------------------------------------------------------ */
/* This include file is always included by decSingle and decDouble, */ /* This include file is always included by decSingle and decDouble, */
/* and therefore also holds useful constants used by all three. */ /* and therefore also holds useful constants used by all three. */
...@@ -59,11 +57,14 @@ ...@@ -59,11 +57,14 @@
/* Required include */ /* Required include */
#include "decContext.h" #include "decContext.h"
/* The decQuad decimal 128-bit type, accessible by various types */ /* The decQuad decimal 128-bit type, accessible by all sizes */
typedef union { typedef union {
uint8_t bytes[DECQUAD_Bytes]; /* fields: 1, 5, 12, 110 bits */ uint8_t bytes[DECQUAD_Bytes]; /* fields: 1, 5, 12, 110 bits */
uint16_t shorts[DECQUAD_Bytes/2]; uint16_t shorts[DECQUAD_Bytes/2];
uint32_t words[DECQUAD_Bytes/4]; uint32_t words[DECQUAD_Bytes/4];
#if DECUSE64
uint64_t longs[DECQUAD_Bytes/8];
#endif
} decQuad; } decQuad;
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
...@@ -99,6 +100,7 @@ ...@@ -99,6 +100,7 @@
extern decQuad * decQuadFromBCD(decQuad *, int32_t, const uint8_t *, int32_t); extern decQuad * decQuadFromBCD(decQuad *, int32_t, const uint8_t *, int32_t);
extern decQuad * decQuadFromInt32(decQuad *, int32_t); extern decQuad * decQuadFromInt32(decQuad *, int32_t);
extern decQuad * decQuadFromPacked(decQuad *, int32_t, const uint8_t *); extern decQuad * decQuadFromPacked(decQuad *, int32_t, const uint8_t *);
extern decQuad * decQuadFromPackedChecked(decQuad *, int32_t, const uint8_t *);
extern decQuad * decQuadFromString(decQuad *, const char *, decContext *); extern decQuad * decQuadFromString(decQuad *, const char *, decContext *);
extern decQuad * decQuadFromUInt32(decQuad *, uint32_t); extern decQuad * decQuadFromUInt32(decQuad *, uint32_t);
extern int32_t decQuadGetCoefficient(const decQuad *, uint8_t *); extern int32_t decQuadGetCoefficient(const decQuad *, uint8_t *);
...@@ -182,7 +184,8 @@ ...@@ -182,7 +184,8 @@
/* decNumber conversions; these are implemented as macros so as not */ /* decNumber conversions; these are implemented as macros so as not */
/* to force a dependency on decimal128 and decNumber in decQuad. */ /* to force a dependency on decimal128 and decNumber in decQuad. */
/* decQuadFromNumber returns a decimal128 * to avoid warnings. */
#define decQuadToNumber(dq, dn) decimal128ToNumber((decimal128 *)(dq), dn) #define decQuadToNumber(dq, dn) decimal128ToNumber((decimal128 *)(dq), dn)
#define decQuadFromNumber(dq, dn, set) (decQuad *)decimal128FromNumber((decimal128 *)(dq), dn, set) #define decQuadFromNumber(dq, dn, set) decimal128FromNumber((decimal128 *)(dq), dn, set)
#endif #endif
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* decSingle.c -- decSingle operations module */ /* decSingle.c -- decSingle operations module */
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* This module comprises decSingle operations (including conversions) */
/* ------------------------------------------------------------------ */
#include "decContext.h" /* public includes */ #include "decContext.h" /* public includes */
#include "decSingle.h" /* public includes */ #include "decSingle.h" /* public includes */
...@@ -61,6 +59,7 @@ ...@@ -61,6 +59,7 @@
/* Utility (binary results, extractors, etc.) */ /* Utility (binary results, extractors, etc.) */
#define decFloatFromBCD decSingleFromBCD #define decFloatFromBCD decSingleFromBCD
#define decFloatFromPacked decSingleFromPacked #define decFloatFromPacked decSingleFromPacked
#define decFloatFromPackedChecked decSingleFromPackedChecked
#define decFloatFromString decSingleFromString #define decFloatFromString decSingleFromString
#define decFloatFromWider decSingleFromWider #define decFloatFromWider decSingleFromWider
#define decFloatGetCoefficient decSingleGetCoefficient #define decFloatGetCoefficient decSingleGetCoefficient
......
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* decSingle.h -- Decimal 32-bit format module header */ /* decSingle.h -- Decimal 32-bit format module header */
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* Please see decFloats.h for an overview and documentation details. */
/* ------------------------------------------------------------------ */
#if !defined(DECSINGLE) #if !defined(DECSINGLE)
#define DECSINGLE #define DECSINGLE
...@@ -59,7 +57,7 @@ ...@@ -59,7 +57,7 @@
#include "decQuad.h" #include "decQuad.h"
#include "decDouble.h" #include "decDouble.h"
/* The decSingle decimal 32-bit type, accessible by various types */ /* The decSingle decimal 32-bit type, accessible by all sizes */
typedef union { typedef union {
uint8_t bytes[DECSINGLE_Bytes]; /* fields: 1, 5, 6, 20 bits */ uint8_t bytes[DECSINGLE_Bytes]; /* fields: 1, 5, 6, 20 bits */
uint16_t shorts[DECSINGLE_Bytes/2]; uint16_t shorts[DECSINGLE_Bytes/2];
...@@ -75,6 +73,7 @@ ...@@ -75,6 +73,7 @@
/* Utilities (binary argument(s) or result, extractors, etc.) */ /* Utilities (binary argument(s) or result, extractors, etc.) */
extern decSingle * decSingleFromBCD(decSingle *, int32_t, const uint8_t *, int32_t); extern decSingle * decSingleFromBCD(decSingle *, int32_t, const uint8_t *, int32_t);
extern decSingle * decSingleFromPacked(decSingle *, int32_t, const uint8_t *); extern decSingle * decSingleFromPacked(decSingle *, int32_t, const uint8_t *);
extern decSingle * decSingleFromPackedChecked(decSingle *, int32_t, const uint8_t *);
extern decSingle * decSingleFromString(decSingle *, const char *, decContext *); extern decSingle * decSingleFromString(decSingle *, const char *, decContext *);
extern decSingle * decSingleFromWider(decSingle *, const decDouble *, decContext *); extern decSingle * decSingleFromWider(decSingle *, const decDouble *, decContext *);
extern int32_t decSingleGetCoefficient(const decSingle *, uint8_t *); extern int32_t decSingleGetCoefficient(const decSingle *, uint8_t *);
...@@ -97,7 +96,8 @@ ...@@ -97,7 +96,8 @@
/* decNumber conversions; these are implemented as macros so as not */ /* decNumber conversions; these are implemented as macros so as not */
/* to force a dependency on decimal32 and decNumber in decSingle. */ /* to force a dependency on decimal32 and decNumber in decSingle. */
/* decSingleFromNumber returns a decimal32 * to avoid warnings. */
#define decSingleToNumber(dq, dn) decimal32ToNumber((decimal32 *)(dq), dn) #define decSingleToNumber(dq, dn) decimal32ToNumber((decimal32 *)(dq), dn)
#define decSingleFromNumber(dq, dn, set) (decSingle *)decimal32FromNumber((decimal32 *)(dq), dn, set) #define decSingleFromNumber(dq, dn, set) decimal32FromNumber((decimal32 *)(dq), dn, set)
#endif #endif
...@@ -89,8 +89,8 @@ decimal128 * decimal128FromNumber(decimal128 *d128, const decNumber *dn, ...@@ -89,8 +89,8 @@ decimal128 * decimal128FromNumber(decimal128 *d128, const decNumber *dn,
Int ae; /* adjusted exponent */ Int ae; /* adjusted exponent */
decNumber dw; /* work */ decNumber dw; /* work */
decContext dc; /* .. */ decContext dc; /* .. */
uInt *pu; /* .. */
uInt comb, exp; /* .. */ uInt comb, exp; /* .. */
uInt uiwork; /* for macros */
uInt targar[4]={0,0,0,0}; /* target 128-bit */ uInt targar[4]={0,0,0,0}; /* target 128-bit */
#define targhi targar[3] /* name the word with the sign */ #define targhi targar[3] /* name the word with the sign */
#define targmh targar[2] /* name the words */ #define targmh targar[2] /* name the words */
...@@ -172,18 +172,19 @@ decimal128 * decimal128FromNumber(decimal128 *d128, const decNumber *dn, ...@@ -172,18 +172,19 @@ decimal128 * decimal128FromNumber(decimal128 *d128, const decNumber *dn,
if (dn->bits&DECNEG) targhi|=0x80000000; /* add sign bit */ if (dn->bits&DECNEG) targhi|=0x80000000; /* add sign bit */
/* now write to storage; this is endian */ /* now write to storage; this is endian */
pu=(uInt *)d128->bytes; /* overlay */
if (DECLITEND) { if (DECLITEND) {
pu[0]=targlo; /* directly store the low int */ /* lo -> hi */
pu[1]=targml; /* then the mid-low */ UBFROMUI(d128->bytes, targlo);
pu[2]=targmh; /* then the mid-high */ UBFROMUI(d128->bytes+4, targml);
pu[3]=targhi; /* then the high int */ UBFROMUI(d128->bytes+8, targmh);
UBFROMUI(d128->bytes+12, targhi);
} }
else { else {
pu[0]=targhi; /* directly store the high int */ /* hi -> lo */
pu[1]=targmh; /* then the mid-high */ UBFROMUI(d128->bytes, targhi);
pu[2]=targml; /* then the mid-low */ UBFROMUI(d128->bytes+4, targmh);
pu[3]=targlo; /* then the low int */ UBFROMUI(d128->bytes+8, targml);
UBFROMUI(d128->bytes+12, targlo);
} }
if (status!=0) decContextSetStatus(set, status); /* pass on status */ if (status!=0) decContextSetStatus(set, status); /* pass on status */
...@@ -201,8 +202,8 @@ decNumber * decimal128ToNumber(const decimal128 *d128, decNumber *dn) { ...@@ -201,8 +202,8 @@ decNumber * decimal128ToNumber(const decimal128 *d128, decNumber *dn) {
uInt msd; /* coefficient MSD */ uInt msd; /* coefficient MSD */
uInt exp; /* exponent top two bits */ uInt exp; /* exponent top two bits */
uInt comb; /* combination field */ uInt comb; /* combination field */
const uInt *pu; /* work */ Int need; /* work */
Int need; /* .. */ uInt uiwork; /* for macros */
uInt sourar[4]; /* source 128-bit */ uInt sourar[4]; /* source 128-bit */
#define sourhi sourar[3] /* name the word with the sign */ #define sourhi sourar[3] /* name the word with the sign */
#define sourmh sourar[2] /* and the mid-high word */ #define sourmh sourar[2] /* and the mid-high word */
...@@ -210,18 +211,17 @@ decNumber * decimal128ToNumber(const decimal128 *d128, decNumber *dn) { ...@@ -210,18 +211,17 @@ decNumber * decimal128ToNumber(const decimal128 *d128, decNumber *dn) {
#define sourlo sourar[0] /* and the lowest word */ #define sourlo sourar[0] /* and the lowest word */
/* load source from storage; this is endian */ /* load source from storage; this is endian */
pu=(const uInt *)d128->bytes; /* overlay */
if (DECLITEND) { if (DECLITEND) {
sourlo=pu[0]; /* directly load the low int */ sourlo=UBTOUI(d128->bytes ); /* directly load the low int */
sourml=pu[1]; /* then the mid-low */ sourml=UBTOUI(d128->bytes+4 ); /* then the mid-low */
sourmh=pu[2]; /* then the mid-high */ sourmh=UBTOUI(d128->bytes+8 ); /* then the mid-high */
sourhi=pu[3]; /* then the high int */ sourhi=UBTOUI(d128->bytes+12); /* then the high int */
} }
else { else {
sourhi=pu[0]; /* directly load the high int */ sourhi=UBTOUI(d128->bytes ); /* directly load the high int */
sourmh=pu[1]; /* then the mid-high */ sourmh=UBTOUI(d128->bytes+4 ); /* then the mid-high */
sourml=pu[2]; /* then the mid-low */ sourml=UBTOUI(d128->bytes+8 ); /* then the mid-low */
sourlo=pu[3]; /* then the low int */ sourlo=UBTOUI(d128->bytes+12); /* then the low int */
} }
comb=(sourhi>>26)&0x1f; /* combination field */ comb=(sourhi>>26)&0x1f; /* combination field */
...@@ -291,11 +291,11 @@ char * decimal128ToString(const decimal128 *d128, char *string){ ...@@ -291,11 +291,11 @@ char * decimal128ToString(const decimal128 *d128, char *string){
uInt comb; /* combination field */ uInt comb; /* combination field */
char *cstart; /* coefficient start */ char *cstart; /* coefficient start */
char *c; /* output pointer in string */ char *c; /* output pointer in string */
const uInt *pu; /* work */ const uByte *u; /* work */
char *s, *t; /* .. (source, target) */ char *s, *t; /* .. (source, target) */
Int dpd; /* .. */ Int dpd; /* .. */
Int pre, e; /* .. */ Int pre, e; /* .. */
const uByte *u; /* .. */ uInt uiwork; /* for macros */
uInt sourar[4]; /* source 128-bit */ uInt sourar[4]; /* source 128-bit */
#define sourhi sourar[3] /* name the word with the sign */ #define sourhi sourar[3] /* name the word with the sign */
...@@ -304,18 +304,17 @@ char * decimal128ToString(const decimal128 *d128, char *string){ ...@@ -304,18 +304,17 @@ char * decimal128ToString(const decimal128 *d128, char *string){
#define sourlo sourar[0] /* and the lowest word */ #define sourlo sourar[0] /* and the lowest word */
/* load source from storage; this is endian */ /* load source from storage; this is endian */
pu=(const uInt *)d128->bytes; /* overlay */
if (DECLITEND) { if (DECLITEND) {
sourlo=pu[0]; /* directly load the low int */ sourlo=UBTOUI(d128->bytes ); /* directly load the low int */
sourml=pu[1]; /* then the mid-low */ sourml=UBTOUI(d128->bytes+4 ); /* then the mid-low */
sourmh=pu[2]; /* then the mid-high */ sourmh=UBTOUI(d128->bytes+8 ); /* then the mid-high */
sourhi=pu[3]; /* then the high int */ sourhi=UBTOUI(d128->bytes+12); /* then the high int */
} }
else { else {
sourhi=pu[0]; /* directly load the high int */ sourhi=UBTOUI(d128->bytes ); /* directly load the high int */
sourmh=pu[1]; /* then the mid-high */ sourmh=UBTOUI(d128->bytes+4 ); /* then the mid-high */
sourml=pu[2]; /* then the mid-low */ sourml=UBTOUI(d128->bytes+8 ); /* then the mid-low */
sourlo=pu[3]; /* then the low int */ sourlo=UBTOUI(d128->bytes+12); /* then the low int */
} }
c=string; /* where result will go */ c=string; /* where result will go */
...@@ -483,7 +482,7 @@ decimal128 * decimal128FromString(decimal128 *result, const char *string, ...@@ -483,7 +482,7 @@ decimal128 * decimal128FromString(decimal128 *result, const char *string,
/* returns 1 if the encoding of d128 is canonical, 0 otherwise */ /* returns 1 if the encoding of d128 is canonical, 0 otherwise */
/* No error is possible. */ /* No error is possible. */
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
uint32_t decimal128IsCanonical(const decimal128 *d128) { uInt decimal128IsCanonical(const decimal128 *d128) {
decNumber dn; /* work */ decNumber dn; /* work */
decimal128 canon; /* .. */ decimal128 canon; /* .. */
decContext dc; /* .. */ decContext dc; /* .. */
...@@ -532,9 +531,9 @@ decimal128 * decimal128Canonical(decimal128 *result, const decimal128 *d128) { ...@@ -532,9 +531,9 @@ decimal128 * decimal128Canonical(decimal128 *result, const decimal128 *d128) {
/* This assumes range has been checked and exponent previously 0; */ /* This assumes range has been checked and exponent previously 0; */
/* type of exponent must be unsigned */ /* type of exponent must be unsigned */
#define decimal128SetExpCon(d, e) { \ #define decimal128SetExpCon(d, e) { \
(d)->bytes[0]|=(uint8_t)((e)>>10); \ (d)->bytes[0]|=(uByte)((e)>>10); \
(d)->bytes[1] =(uint8_t)(((e)&0x3fc)>>2); \ (d)->bytes[1] =(uByte)(((e)&0x3fc)>>2); \
(d)->bytes[2]|=(uint8_t)(((e)&0x03)<<6);} (d)->bytes[2]|=(uByte)(((e)&0x03)<<6);}
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* decimal128Show -- display a decimal128 in hexadecimal [debug aid] */ /* decimal128Show -- display a decimal128 in hexadecimal [debug aid] */
......
...@@ -76,13 +76,13 @@ ...@@ -76,13 +76,13 @@
#define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */ #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */
#endif #endif
#include "decimal128Local.h" #include "decimal128Local.h"
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
/* Routines */ /* Routines */
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
#include "decimal128Symbols.h" #include "decimal128Symbols.h"
/* String conversions */ /* String conversions */
decimal128 * decimal128FromString(decimal128 *, const char *, decContext *); decimal128 * decimal128FromString(decimal128 *, const char *, decContext *);
......
...@@ -89,8 +89,8 @@ decimal32 * decimal32FromNumber(decimal32 *d32, const decNumber *dn, ...@@ -89,8 +89,8 @@ decimal32 * decimal32FromNumber(decimal32 *d32, const decNumber *dn,
Int ae; /* adjusted exponent */ Int ae; /* adjusted exponent */
decNumber dw; /* work */ decNumber dw; /* work */
decContext dc; /* .. */ decContext dc; /* .. */
uInt *pu; /* .. */
uInt comb, exp; /* .. */ uInt comb, exp; /* .. */
uInt uiwork; /* for macros */
uInt targ=0; /* target 32-bit */ uInt targ=0; /* target 32-bit */
/* If the number has too many digits, or the exponent could be */ /* If the number has too many digits, or the exponent could be */
...@@ -175,8 +175,7 @@ decimal32 * decimal32FromNumber(decimal32 *d32, const decNumber *dn, ...@@ -175,8 +175,7 @@ decimal32 * decimal32FromNumber(decimal32 *d32, const decNumber *dn,
if (dn->bits&DECNEG) targ|=0x80000000; /* add sign bit */ if (dn->bits&DECNEG) targ|=0x80000000; /* add sign bit */
/* now write to storage; this is endian */ /* now write to storage; this is endian */
pu=(uInt *)d32->bytes; /* overlay */ UBFROMUI(d32->bytes, targ); /* directly store the int */
*pu=targ; /* directly store the int */
if (status!=0) decContextSetStatus(set, status); /* pass on status */ if (status!=0) decContextSetStatus(set, status); /* pass on status */
/* decimal32Show(d32); */ /* decimal32Show(d32); */
...@@ -194,11 +193,10 @@ decNumber * decimal32ToNumber(const decimal32 *d32, decNumber *dn) { ...@@ -194,11 +193,10 @@ decNumber * decimal32ToNumber(const decimal32 *d32, decNumber *dn) {
uInt exp; /* exponent top two bits */ uInt exp; /* exponent top two bits */
uInt comb; /* combination field */ uInt comb; /* combination field */
uInt sour; /* source 32-bit */ uInt sour; /* source 32-bit */
const uInt *pu; /* work */ uInt uiwork; /* for macros */
/* load source from storage; this is endian */ /* load source from storage; this is endian */
pu=(const uInt *)d32->bytes; /* overlay */ sour=UBTOUI(d32->bytes); /* directly load the int */
sour=*pu; /* directly load the int */
comb=(sour>>26)&0x1f; /* combination field */ comb=(sour>>26)&0x1f; /* combination field */
...@@ -264,16 +262,15 @@ char * decimal32ToString(const decimal32 *d32, char *string){ ...@@ -264,16 +262,15 @@ char * decimal32ToString(const decimal32 *d32, char *string){
uInt comb; /* combination field */ uInt comb; /* combination field */
char *cstart; /* coefficient start */ char *cstart; /* coefficient start */
char *c; /* output pointer in string */ char *c; /* output pointer in string */
const uInt *pu; /* work */ const uByte *u; /* work */
const uByte *u; /* .. */
char *s, *t; /* .. (source, target) */ char *s, *t; /* .. (source, target) */
Int dpd; /* .. */ Int dpd; /* .. */
Int pre, e; /* .. */ Int pre, e; /* .. */
uInt uiwork; /* for macros */
uInt sour; /* source 32-bit */ uInt sour; /* source 32-bit */
/* load source from storage; this is endian */ /* load source from storage; this is endian */
pu=(const uInt *)d32->bytes; /* overlay */ sour=UBTOUI(d32->bytes); /* directly load the int */
sour=*pu; /* directly load the int */
c=string; /* where result will go */ c=string; /* where result will go */
if (((Int)sour)<0) *c++='-'; /* handle sign */ if (((Int)sour)<0) *c++='-'; /* handle sign */
...@@ -412,7 +409,7 @@ decimal32 * decimal32FromString(decimal32 *result, const char *string, ...@@ -412,7 +409,7 @@ decimal32 * decimal32FromString(decimal32 *result, const char *string,
/* returns 1 if the encoding of d32 is canonical, 0 otherwise */ /* returns 1 if the encoding of d32 is canonical, 0 otherwise */
/* No error is possible. */ /* No error is possible. */
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
uint32_t decimal32IsCanonical(const decimal32 *d32) { uInt decimal32IsCanonical(const decimal32 *d32) {
decNumber dn; /* work */ decNumber dn; /* work */
decimal32 canon; /* .. */ decimal32 canon; /* .. */
decContext dc; /* .. */ decContext dc; /* .. */
...@@ -460,8 +457,8 @@ decimal32 * decimal32Canonical(decimal32 *result, const decimal32 *d32) { ...@@ -460,8 +457,8 @@ decimal32 * decimal32Canonical(decimal32 *result, const decimal32 *d32) {
/* This assumes range has been checked and exponent previously 0; */ /* This assumes range has been checked and exponent previously 0; */
/* type of exponent must be unsigned */ /* type of exponent must be unsigned */
#define decimal32SetExpCon(d, e) { \ #define decimal32SetExpCon(d, e) { \
(d)->bytes[0]|=(uint8_t)((e)>>4); \ (d)->bytes[0]|=(uByte)((e)>>4); \
(d)->bytes[1]|=(uint8_t)(((e)&0x0F)<<4);} (d)->bytes[1]|=(uByte)(((e)&0x0F)<<4);}
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* decimal32Show -- display a decimal32 in hexadecimal [debug aid] */ /* decimal32Show -- display a decimal32 in hexadecimal [debug aid] */
......
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
/* Routines */ /* Routines */
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
#include "decimal32Symbols.h" #include "decimal32Symbols.h"
/* String conversions */ /* String conversions */
decimal32 * decimal32FromString(decimal32 *, const char *, decContext *); decimal32 * decimal32FromString(decimal32 *, const char *, decContext *);
......
...@@ -95,8 +95,8 @@ decimal64 * decimal64FromNumber(decimal64 *d64, const decNumber *dn, ...@@ -95,8 +95,8 @@ decimal64 * decimal64FromNumber(decimal64 *d64, const decNumber *dn,
Int ae; /* adjusted exponent */ Int ae; /* adjusted exponent */
decNumber dw; /* work */ decNumber dw; /* work */
decContext dc; /* .. */ decContext dc; /* .. */
uInt *pu; /* .. */
uInt comb, exp; /* .. */ uInt comb, exp; /* .. */
uInt uiwork; /* for macros */
uInt targar[2]={0, 0}; /* target 64-bit */ uInt targar[2]={0, 0}; /* target 64-bit */
#define targhi targar[1] /* name the word with the sign */ #define targhi targar[1] /* name the word with the sign */
#define targlo targar[0] /* and the other */ #define targlo targar[0] /* and the other */
...@@ -193,14 +193,15 @@ decimal64 * decimal64FromNumber(decimal64 *d64, const decNumber *dn, ...@@ -193,14 +193,15 @@ decimal64 * decimal64FromNumber(decimal64 *d64, const decNumber *dn,
if (dn->bits&DECNEG) targhi|=0x80000000; /* add sign bit */ if (dn->bits&DECNEG) targhi|=0x80000000; /* add sign bit */
/* now write to storage; this is now always endian */ /* now write to storage; this is now always endian */
pu=(uInt *)d64->bytes; /* overlay */
if (DECLITEND) { if (DECLITEND) {
pu[0]=targar[0]; /* directly store the low int */ /* lo int then hi */
pu[1]=targar[1]; /* then the high int */ UBFROMUI(d64->bytes, targar[0]);
UBFROMUI(d64->bytes+4, targar[1]);
} }
else { else {
pu[0]=targar[1]; /* directly store the high int */ /* hi int then lo */
pu[1]=targar[0]; /* then the low int */ UBFROMUI(d64->bytes, targar[1]);
UBFROMUI(d64->bytes+4, targar[0]);
} }
if (status!=0) decContextSetStatus(set, status); /* pass on status */ if (status!=0) decContextSetStatus(set, status); /* pass on status */
...@@ -218,21 +219,20 @@ decNumber * decimal64ToNumber(const decimal64 *d64, decNumber *dn) { ...@@ -218,21 +219,20 @@ decNumber * decimal64ToNumber(const decimal64 *d64, decNumber *dn) {
uInt msd; /* coefficient MSD */ uInt msd; /* coefficient MSD */
uInt exp; /* exponent top two bits */ uInt exp; /* exponent top two bits */
uInt comb; /* combination field */ uInt comb; /* combination field */
const uInt *pu; /* work */ Int need; /* work */
Int need; /* .. */ uInt uiwork; /* for macros */
uInt sourar[2]; /* source 64-bit */ uInt sourar[2]; /* source 64-bit */
#define sourhi sourar[1] /* name the word with the sign */ #define sourhi sourar[1] /* name the word with the sign */
#define sourlo sourar[0] /* and the lower word */ #define sourlo sourar[0] /* and the lower word */
/* load source from storage; this is endian */ /* load source from storage; this is endian */
pu=(const uInt *)d64->bytes; /* overlay */
if (DECLITEND) { if (DECLITEND) {
sourlo=pu[0]; /* directly load the low int */ sourlo=UBTOUI(d64->bytes ); /* directly load the low int */
sourhi=pu[1]; /* then the high int */ sourhi=UBTOUI(d64->bytes+4); /* then the high int */
} }
else { else {
sourhi=pu[0]; /* directly load the high int */ sourhi=UBTOUI(d64->bytes ); /* directly load the high int */
sourlo=pu[1]; /* then the low int */ sourlo=UBTOUI(d64->bytes+4); /* then the low int */
} }
comb=(sourhi>>26)&0x1f; /* combination field */ comb=(sourhi>>26)&0x1f; /* combination field */
...@@ -307,25 +307,24 @@ char * decimal64ToString(const decimal64 *d64, char *string){ ...@@ -307,25 +307,24 @@ char * decimal64ToString(const decimal64 *d64, char *string){
uInt comb; /* combination field */ uInt comb; /* combination field */
char *cstart; /* coefficient start */ char *cstart; /* coefficient start */
char *c; /* output pointer in string */ char *c; /* output pointer in string */
const uInt *pu; /* work */ const uByte *u; /* work */
char *s, *t; /* .. (source, target) */ char *s, *t; /* .. (source, target) */
Int dpd; /* .. */ Int dpd; /* .. */
Int pre, e; /* .. */ Int pre, e; /* .. */
const uByte *u; /* .. */ uInt uiwork; /* for macros */
uInt sourar[2]; /* source 64-bit */ uInt sourar[2]; /* source 64-bit */
#define sourhi sourar[1] /* name the word with the sign */ #define sourhi sourar[1] /* name the word with the sign */
#define sourlo sourar[0] /* and the lower word */ #define sourlo sourar[0] /* and the lower word */
/* load source from storage; this is endian */ /* load source from storage; this is endian */
pu=(const uInt *)d64->bytes; /* overlay */
if (DECLITEND) { if (DECLITEND) {
sourlo=pu[0]; /* directly load the low int */ sourlo=UBTOUI(d64->bytes ); /* directly load the low int */
sourhi=pu[1]; /* then the high int */ sourhi=UBTOUI(d64->bytes+4); /* then the high int */
} }
else { else {
sourhi=pu[0]; /* directly load the high int */ sourhi=UBTOUI(d64->bytes ); /* directly load the high int */
sourlo=pu[1]; /* then the low int */ sourlo=UBTOUI(d64->bytes+4); /* then the low int */
} }
c=string; /* where result will go */ c=string; /* where result will go */
...@@ -472,7 +471,7 @@ decimal64 * decimal64FromString(decimal64 *result, const char *string, ...@@ -472,7 +471,7 @@ decimal64 * decimal64FromString(decimal64 *result, const char *string,
/* returns 1 if the encoding of d64 is canonical, 0 otherwise */ /* returns 1 if the encoding of d64 is canonical, 0 otherwise */
/* No error is possible. */ /* No error is possible. */
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
uint32_t decimal64IsCanonical(const decimal64 *d64) { uInt decimal64IsCanonical(const decimal64 *d64) {
decNumber dn; /* work */ decNumber dn; /* work */
decimal64 canon; /* .. */ decimal64 canon; /* .. */
decContext dc; /* .. */ decContext dc; /* .. */
...@@ -520,8 +519,8 @@ decimal64 * decimal64Canonical(decimal64 *result, const decimal64 *d64) { ...@@ -520,8 +519,8 @@ decimal64 * decimal64Canonical(decimal64 *result, const decimal64 *d64) {
/* This assumes range has been checked and exponent previously 0; */ /* This assumes range has been checked and exponent previously 0; */
/* type of exponent must be unsigned */ /* type of exponent must be unsigned */
#define decimal64SetExpCon(d, e) { \ #define decimal64SetExpCon(d, e) { \
(d)->bytes[0]|=(uint8_t)((e)>>6); \ (d)->bytes[0]|=(uByte)((e)>>6); \
(d)->bytes[1]|=(uint8_t)(((e)&0x3F)<<2);} (d)->bytes[1]|=(uByte)(((e)&0x3F)<<2);}
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/* decimal64Show -- display a decimal64 in hexadecimal [debug aid] */ /* decimal64Show -- display a decimal64 in hexadecimal [debug aid] */
......
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
/* Routines */ /* Routines */
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
#include "decimal64Symbols.h" #include "decimal64Symbols.h"
/* String conversions */ /* String conversions */
decimal64 * decimal64FromString(decimal64 *, const char *, decContext *); decimal64 * decimal64FromString(decimal64 *, const char *, decContext *);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment