aboutsummaryrefslogtreecommitdiff
path: root/libdecnumber/dpd/decimal32.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdecnumber/dpd/decimal32.c')
-rw-r--r--libdecnumber/dpd/decimal32.c83
1 files changed, 40 insertions, 43 deletions
diff --git a/libdecnumber/dpd/decimal32.c b/libdecnumber/dpd/decimal32.c
index d8e3f59..eefd71c 100644
--- a/libdecnumber/dpd/decimal32.c
+++ b/libdecnumber/dpd/decimal32.c
@@ -29,7 +29,7 @@
02110-1301, USA. */
/* ------------------------------------------------------------------ */
-/* Decimal 32-bit format module */
+/* Decimal 32-bit format module */
/* ------------------------------------------------------------------ */
/* This module comprises the routines for decimal32 format numbers. */
/* Conversions are supplied to and from decNumber and String. */
@@ -42,8 +42,8 @@
#include <string.h> /* [for memset/memcpy] */
#include <stdio.h> /* [for printf] */
-#include "dconfig.h" /* GCC definitions */
-#define DECNUMDIGITS 7 /* make decNumbers with space for 7 */
+#include "dconfig.h" /* GCC definitions */
+#define DECNUMDIGITS 7 /* make decNumbers with space for 7 */
#include "decNumber.h" /* base number library */
#include "decNumberLocal.h" /* decNumber local types, etc. */
#include "decimal32.h" /* our primary include */
@@ -69,9 +69,9 @@ extern void decNumberShow(const decNumber *); /* .. */
/* ------------------------------------------------------------------ */
/* decimal32FromNumber -- convert decNumber to decimal32 */
/* */
-/* ds is the target decimal32 */
+/* ds is the target decimal32 */
/* dn is the source number (assumed valid) */
-/* set is the context, used only for reporting errors */
+/* set is the context, used only for reporting errors */
/* */
/* The set argument is used only for status reporting and for the */
/* rounding mode (used if the coefficient is more than DECIMAL32_Pmax */
@@ -89,8 +89,8 @@ decimal32 * decimal32FromNumber(decimal32 *d32, const decNumber *dn,
Int ae; /* adjusted exponent */
decNumber dw; /* work */
decContext dc; /* .. */
- uInt *pu; /* .. */
uInt comb, exp; /* .. */
+ uInt uiwork; /* for macros */
uInt targ=0; /* target 32-bit */
/* If the number has too many digits, or the exponent could be */
@@ -98,9 +98,9 @@ decimal32 * decimal32FromNumber(decimal32 *d32, const decNumber *dn,
/* constraints. This could push the number to Infinity or zero, */
/* so this check and rounding must be done before generating the */
/* decimal32] */
- ae=dn->exponent+dn->digits-1; /* [0 if special] */
- if (dn->digits>DECIMAL32_Pmax /* too many digits */
- || ae>DECIMAL32_Emax /* likely overflow */
+ ae=dn->exponent+dn->digits-1; /* [0 if special] */
+ if (dn->digits>DECIMAL32_Pmax /* too many digits */
+ || ae>DECIMAL32_Emax /* likely overflow */
|| ae<DECIMAL32_Emin) { /* likely underflow */
decContextDefault(&dc, DEC_INIT_DECIMAL32); /* [no traps] */
dc.round=set->round; /* use supplied rounding */
@@ -114,7 +114,7 @@ decimal32 * decimal32FromNumber(decimal32 *d32, const decNumber *dn,
if (dn->bits&DECSPECIAL) { /* a special value */
if (dn->bits&DECINF) targ=DECIMAL_Inf<<24;
else { /* sNaN or qNaN */
- if ((*dn->lsu!=0 || dn->digits>1) /* non-zero coefficient */
+ if ((*dn->lsu!=0 || dn->digits>1) /* non-zero coefficient */
&& (dn->digits<DECIMAL32_Pmax)) { /* coefficient fits */
decDigitsToDPD(dn, &targ, 0);
}
@@ -140,7 +140,7 @@ decimal32 * decimal32FromNumber(decimal32 *d32, const decNumber *dn,
comb=(exp>>3) & 0x18; /* msd=0, exp top 2 bits .. */
}
else { /* non-zero finite number */
- uInt msd; /* work */
+ uInt msd; /* work */
Int pad=0; /* coefficient pad digits */
/* the dn is known to fit, but it may need to be padded */
@@ -175,8 +175,7 @@ decimal32 * decimal32FromNumber(decimal32 *d32, const decNumber *dn,
if (dn->bits&DECNEG) targ|=0x80000000; /* add sign bit */
/* now write to storage; this is endian */
- pu=(uInt *)d32->bytes; /* overlay */
- *pu=targ; /* directly store the int */
+ UBFROMUI(d32->bytes, targ); /* directly store the int */
if (status!=0) decContextSetStatus(set, status); /* pass on status */
/* decimal32Show(d32); */
@@ -194,13 +193,12 @@ decNumber * decimal32ToNumber(const decimal32 *d32, decNumber *dn) {
uInt exp; /* exponent top two bits */
uInt comb; /* combination field */
uInt sour; /* source 32-bit */
- const uInt *pu; /* work */
+ uInt uiwork; /* for macros */
/* load source from storage; this is endian */
- pu=(const uInt *)d32->bytes; /* overlay */
- sour=*pu; /* directly load the int */
+ sour=UBTOUI(d32->bytes); /* directly load the int */
- comb=(sour>>26)&0x1f; /* combination field */
+ comb=(sour>>26)&0x1f; /* combination field */
decNumberZero(dn); /* clean number */
if (sour&0x80000000) dn->bits=DECNEG; /* set sign if negative */
@@ -208,7 +206,7 @@ decNumber * decimal32ToNumber(const decimal32 *d32, decNumber *dn) {
msd=COMBMSD[comb]; /* decode the combination field */
exp=COMBEXP[comb]; /* .. */
- if (exp==3) { /* is a special */
+ if (exp==3) { /* is a special */
if (msd==0) {
dn->bits|=DECINF;
return dn; /* no coefficient needed */
@@ -229,7 +227,7 @@ decNumber * decimal32ToNumber(const decimal32 *d32, decNumber *dn) {
return dn;
}
/* msd=0 */
- if (!sour) return dn; /* easy: coefficient is 0 */
+ if (!sour) return dn; /* easy: coefficient is 0 */
if (sour&0x000ffc00) /* need 2 declets? */
decDigitsFromDPD(dn, &sour, 2); /* process 2 declets */
else
@@ -238,11 +236,11 @@ decNumber * decimal32ToNumber(const decimal32 *d32, decNumber *dn) {
} /* decimal32ToNumber */
/* ------------------------------------------------------------------ */
-/* to-scientific-string -- conversion to numeric string */
+/* to-scientific-string -- conversion to numeric string */
/* to-engineering-string -- conversion to numeric string */
/* */
/* decimal32ToString(d32, string); */
-/* decimal32ToEngString(d32, string); */
+/* decimal32ToEngString(d32, string); */
/* */
/* d32 is the decimal32 format number to convert */
/* string is the string where the result will be laid out */
@@ -252,7 +250,7 @@ decNumber * decimal32ToNumber(const decimal32 *d32, decNumber *dn) {
/* No error is possible, and no status can be set. */
/* ------------------------------------------------------------------ */
char * decimal32ToEngString(const decimal32 *d32, char *string){
- decNumber dn; /* work */
+ decNumber dn; /* work */
decimal32ToNumber(d32, &dn);
decNumberToEngString(&dn, string);
return string;
@@ -262,29 +260,28 @@ char * decimal32ToString(const decimal32 *d32, char *string){
uInt msd; /* coefficient MSD */
Int exp; /* exponent top two bits or full */
uInt comb; /* combination field */
- char *cstart; /* coefficient start */
+ char *cstart; /* coefficient start */
char *c; /* output pointer in string */
- const uInt *pu; /* work */
- const uByte *u; /* .. */
+ const uByte *u; /* work */
char *s, *t; /* .. (source, target) */
Int dpd; /* .. */
Int pre, e; /* .. */
+ uInt uiwork; /* for macros */
uInt sour; /* source 32-bit */
/* load source from storage; this is endian */
- pu=(const uInt *)d32->bytes; /* overlay */
- sour=*pu; /* directly load the int */
+ sour=UBTOUI(d32->bytes); /* directly load the int */
c=string; /* where result will go */
if (((Int)sour)<0) *c++='-'; /* handle sign */
- comb=(sour>>26)&0x1f; /* combination field */
+ comb=(sour>>26)&0x1f; /* combination field */
msd=COMBMSD[comb]; /* decode the combination field */
exp=COMBEXP[comb]; /* .. */
if (exp==3) {
if (msd==0) { /* infinity */
- strcpy(c, "Inf");
+ strcpy(c, "Inf");
strcpy(c+3, "inity");
return string; /* easy */
}
@@ -309,18 +306,18 @@ char * decimal32ToString(const decimal32 *d32, char *string){
/* length. We use fixed-length memcpys because variable-length */
/* causes a subroutine call in GCC. (These are length 4 for speed */
/* and are safe because the array has an extra terminator byte.) */
- #define dpd2char u=&BIN2CHAR[DPD2BIN[dpd]*4]; \
+ #define dpd2char u=&BIN2CHAR[DPD2BIN[dpd]*4]; \
if (c!=cstart) {memcpy(c, u+1, 4); c+=3;} \
else if (*u) {memcpy(c, u+4-*u, 4); c+=*u;}
- dpd=(sour>>10)&0x3ff; /* declet 1 */
+ dpd=(sour>>10)&0x3ff; /* declet 1 */
dpd2char;
dpd=(sour)&0x3ff; /* declet 2 */
dpd2char;
if (c==cstart) *c++='0'; /* all zeros -- make 0 */
- if (exp==0) { /* integer or NaN case -- easy */
+ if (exp==0) { /* integer or NaN case -- easy */
*c='\0'; /* terminate */
return string;
}
@@ -348,13 +345,13 @@ char * decimal32ToString(const decimal32 *d32, char *string){
/* finally add the E-part, if needed; it will never be 0, and has */
/* a maximum length of 3 digits (E-101 case) */
if (e!=0) {
- *c++='E'; /* starts with E */
- *c++='+'; /* assume positive */
+ *c++='E'; /* starts with E */
+ *c++='+'; /* assume positive */
if (e<0) {
*(c-1)='-'; /* oops, need '-' */
e=-e; /* uInt, please */
}
- u=&BIN2CHAR[e*4]; /* -> length byte */
+ u=&BIN2CHAR[e*4]; /* -> length byte */
memcpy(c, u+4-*u, 4); /* copy fixed 4 characters [is safe] */
c+=*u; /* bump pointer appropriately */
}
@@ -384,7 +381,7 @@ char * decimal32ToString(const decimal32 *d32, char *string){
/* the conversion */
/* *string is the character string which should contain a valid */
/* number (which may be a special value) */
-/* set is the context */
+/* set is the context */
/* */
/* The context is supplied to this routine is used for error handling */
/* (setting of status and traps) and for the rounding mode, only. */
@@ -393,7 +390,7 @@ char * decimal32ToString(const decimal32 *d32, char *string){
decimal32 * decimal32FromString(decimal32 *result, const char *string,
decContext *set) {
decContext dc; /* work */
- decNumber dn; /* .. */
+ decNumber dn; /* .. */
decContextDefault(&dc, DEC_INIT_DECIMAL32); /* no traps, please */
dc.round=set->round; /* use supplied rounding */
@@ -409,11 +406,11 @@ decimal32 * decimal32FromString(decimal32 *result, const char *string,
/* ------------------------------------------------------------------ */
/* decimal32IsCanonical -- test whether encoding is canonical */
/* d32 is the source decimal32 */
-/* 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. */
/* ------------------------------------------------------------------ */
-uint32_t decimal32IsCanonical(const decimal32 *d32) {
- decNumber dn; /* work */
+uInt decimal32IsCanonical(const decimal32 *d32) {
+ decNumber dn; /* work */
decimal32 canon; /* .. */
decContext dc; /* .. */
decContextDefault(&dc, DEC_INIT_DECIMAL32);
@@ -430,7 +427,7 @@ uint32_t decimal32IsCanonical(const decimal32 *d32) {
/* No error is possible. */
/* ------------------------------------------------------------------ */
decimal32 * decimal32Canonical(decimal32 *result, const decimal32 *d32) {
- decNumber dn; /* work */
+ decNumber dn; /* work */
decContext dc; /* .. */
decContextDefault(&dc, DEC_INIT_DECIMAL32);
decimal32ToNumber(d32, &dn);
@@ -460,8 +457,8 @@ decimal32 * decimal32Canonical(decimal32 *result, const decimal32 *d32) {
/* This assumes range has been checked and exponent previously 0; */
/* type of exponent must be unsigned */
#define decimal32SetExpCon(d, e) { \
- (d)->bytes[0]|=(uint8_t)((e)>>4); \
- (d)->bytes[1]|=(uint8_t)(((e)&0x0F)<<4);}
+ (d)->bytes[0]|=(uByte)((e)>>4); \
+ (d)->bytes[1]|=(uByte)(((e)&0x0F)<<4);}
/* ------------------------------------------------------------------ */
/* decimal32Show -- display a decimal32 in hexadecimal [debug aid] */