Lines Matching +full:fixed +full:- +full:length

1 /* Decimal 128-bit format module for the decNumber C Library.
29 02110-1301, USA. */
31 /* ------------------------------------------------------------------ */
32 /* Decimal 128-bit format module */
33 /* ------------------------------------------------------------------ */
41 /* ------------------------------------------------------------------ */
66 /* ------------------------------------------------------------------ */
67 /* decimal128FromNumber -- convert decNumber to decimal128 */
82 /* ------------------------------------------------------------------ */
91 uInt targar[4]={0,0,0,0}; /* target 128-bit */ in decimal128FromNumber()
102 ae=dn->exponent+dn->digits-1; /* [0 if special] */ in decimal128FromNumber()
103 if (dn->digits>DECIMAL128_Pmax /* too many digits */ in decimal128FromNumber()
107 dc.round=set->round; /* use supplied rounding */ in decimal128FromNumber()
109 /* [this changes -0 to 0, so enforce the sign...] */ in decimal128FromNumber()
110 dw.bits|=dn->bits&DECNEG; in decimal128FromNumber()
115 if (dn->bits&DECSPECIAL) { /* a special value */ in decimal128FromNumber()
116 if (dn->bits&DECINF) targhi=DECIMAL_Inf<<24; in decimal128FromNumber()
118 if ((*dn->lsu!=0 || dn->digits>1) /* non-zero coefficient */ in decimal128FromNumber()
119 && (dn->digits<DECIMAL128_Pmax)) { /* coefficient fits */ in decimal128FromNumber()
122 if (dn->bits&DECNAN) targhi|=DECIMAL_NaN<<24; in decimal128FromNumber()
130 if (dn->exponent<-DECIMAL128_Bias) { in decimal128FromNumber()
135 exp=dn->exponent+DECIMAL128_Bias; /* bias exponent */ in decimal128FromNumber()
143 else { /* non-zero finite number */ in decimal128FromNumber()
148 exp=(uInt)(dn->exponent+DECIMAL128_Bias); /* bias exponent */ in decimal128FromNumber()
149 if (exp>DECIMAL128_Ehigh) { /* fold-down case */ in decimal128FromNumber()
150 pad=exp-DECIMAL128_Ehigh; in decimal128FromNumber()
169 if (dn->bits&DECNEG) targhi|=0x80000000; /* add sign bit */ in decimal128FromNumber()
172 pu=(uInt *)d128->bytes; /* overlay */ in decimal128FromNumber()
175 pu[1]=targml; /* then the mid-low */ in decimal128FromNumber()
176 pu[2]=targmh; /* then the mid-high */ in decimal128FromNumber()
181 pu[1]=targmh; /* then the mid-high */ in decimal128FromNumber()
182 pu[2]=targml; /* then the mid-low */ in decimal128FromNumber()
191 /* ------------------------------------------------------------------ */
192 /* decimal128ToNumber -- convert decimal128 to decNumber */
196 /* ------------------------------------------------------------------ */
203 uInt sourar[4]; /* source 128-bit */ in decimal128ToNumber()
205 #define sourmh sourar[2] /* and the mid-high word */ in decimal128ToNumber()
206 #define sourml sourar[1] /* and the mod-low word */ in decimal128ToNumber()
210 pu=(const uInt *)d128->bytes; /* overlay */ in decimal128ToNumber()
213 sourml=pu[1]; /* then the mid-low */ in decimal128ToNumber()
214 sourmh=pu[2]; /* then the mid-high */ in decimal128ToNumber()
219 sourmh=pu[1]; /* then the mid-high */ in decimal128ToNumber()
220 sourml=pu[2]; /* then the mid-low */ in decimal128ToNumber()
227 if (sourhi&0x80000000) dn->bits=DECNEG; /* set sign if negative */ in decimal128ToNumber()
234 dn->bits|=DECINF; in decimal128ToNumber()
237 else if (sourhi&0x02000000) dn->bits|=DECSNAN; in decimal128ToNumber()
238 else dn->bits|=DECNAN; in decimal128ToNumber()
242 dn->exponent=(exp<<12)+((sourhi>>14)&0xfff)-DECIMAL128_Bias; /* unbiased */ in decimal128ToNumber()
247 if (msd) { /* non-zero msd */ in decimal128ToNumber()
264 /* ------------------------------------------------------------------ */
265 /* to-scientific-string -- conversion to numeric string */
266 /* to-engineering-string -- conversion to numeric string */
277 /* ------------------------------------------------------------------ */
297 uInt sourar[4]; /* source 128-bit */ in decimal128ToString()
299 #define sourmh sourar[2] /* and the mid-high word */ in decimal128ToString()
300 #define sourml sourar[1] /* and the mod-low word */ in decimal128ToString()
304 pu=(const uInt *)d128->bytes; /* overlay */ in decimal128ToString()
307 sourml=pu[1]; /* then the mid-low */ in decimal128ToString()
308 sourmh=pu[2]; /* then the mid-high */ in decimal128ToString()
313 sourmh=pu[1]; /* then the mid-high */ in decimal128ToString()
314 sourml=pu[2]; /* then the mid-low */ in decimal128ToString()
319 if (((Int)sourhi)<0) *c++='-'; /* handle sign */ in decimal128ToString()
339 else exp=(exp<<12)+((sourhi>>14)&0xfff)-DECIMAL128_Bias; /* unbiased */ in decimal128ToString()
343 if (msd) *c++='0'+(char)msd; /* non-zero most significant digit */ in decimal128ToString()
346 /* decoded to binary and then to a 4-char sequence by table lookup; */ in decimal128ToString()
347 /* the 4-chars are a 1-char length (significant digits, except 000 */ in decimal128ToString()
348 /* has length 0). This allows us to left-align the first declet */ in decimal128ToString()
349 /* with non-zero content, then remaining ones are full 3-char */ in decimal128ToString()
350 /* length. We use fixed-length memcpys because variable-length */ in decimal128ToString()
351 /* causes a subroutine call in GCC. (These are length 4 for speed */ in decimal128ToString()
355 else if (*u) {memcpy(c, u+4-*u, 4); c+=*u;} in decimal128ToString()
379 if (c==cstart) *c++='0'; /* all zeros -- make 0 */ in decimal128ToString()
381 if (exp==0) { /* integer or NaN case -- easy */ in decimal128ToString()
386 /* non-0 exponent */ in decimal128ToString()
388 pre=c-cstart+exp; in decimal128ToString()
389 /* [here, pre-exp is the digits count (==1 for zero)] */ in decimal128ToString()
390 if (exp>0 || pre<-5) { /* need exponential form */ in decimal128ToString()
391 e=pre-1; /* calculate E value */ in decimal128ToString()
396 s=c-1; /* source (LSD) */ in decimal128ToString()
401 for (; s>=dotat; s--, t--) *t=*s; /* open the gap; leave t at gap */ in decimal128ToString()
403 c++; /* length increased by one */ in decimal128ToString()
406 /* finally add the E-part, if needed; it will never be 0, and has */ in decimal128ToString()
407 /* a maximum length of 4 digits */ in decimal128ToString()
412 *(c-1)='-'; /* oops, need '-' */ in decimal128ToString()
413 e=-e; /* uInt, please */ in decimal128ToString()
416 u=&BIN2CHAR[e*4]; /* -> length byte */ in decimal128ToString()
417 memcpy(c, u+4-*u, 4); /* copy fixed 4 characters [is safe] */ in decimal128ToString()
420 else { /* 4-digits */ in decimal128ToString()
422 Int rem=e-(1000*thou); /* e%1000 */ in decimal128ToString()
424 u=&BIN2CHAR[rem*4]; /* -> length byte */ in decimal128ToString()
425 memcpy(c, u+1, 4); /* copy fixed 3+1 characters [is safe] */ in decimal128ToString()
434 /* -5<=pre<=0: here for plain 0.ddd or 0.000ddd forms (can never have E) */ in decimal128ToString()
435 t=c+1-pre; in decimal128ToString()
437 for (; s>=cstart; s--, t--) *t=*s; /* shift whole coefficient right */ in decimal128ToString()
446 /* ------------------------------------------------------------------ */
447 /* to-number -- conversion from numeric string */
460 /* ------------------------------------------------------------------ */
467 dc.round=set->round; /* use supplied rounding */ in decimal128FromString()
477 /* ------------------------------------------------------------------ */
478 /* decimal128IsCanonical -- test whether encoding is canonical */
482 /* ------------------------------------------------------------------ */
493 /* ------------------------------------------------------------------ */
494 /* decimal128Canonical -- copy an encoding, ensuring it is canonical */
499 /* ------------------------------------------------------------------ */
512 decimal128 is in network byte order (big-endian) */
514 #define decimal128Sign(d) ((unsigned)(d)->bytes[0]>>7)
517 #define decimal128Comb(d) (((d)->bytes[0] & 0x7c)>>2)
520 #define decimal128ExpCon(d) ((((d)->bytes[0] & 0x03)<<10) \
521 | ((unsigned)(d)->bytes[1]<<2) \
522 | ((unsigned)(d)->bytes[2]>>6))
526 (d)->bytes[0]|=((unsigned)(b)<<7);}
532 (d)->bytes[0]|=(uint8_t)((e)>>10); \
533 (d)->bytes[1] =(uint8_t)(((e)&0x3fc)>>2); \
534 (d)->bytes[2]|=(uint8_t)(((e)&0x03)<<6);}
536 /* ------------------------------------------------------------------ */
537 /* decimal128Show -- display a decimal128 in hexadecimal [debug aid] */
538 /* d128 -- the number to show */
539 /* ------------------------------------------------------------------ */
547 sprintf(&buf[j], "%02x", d128->bytes[15-i]); in decimal128Show()
550 d128->bytes[15]>>7, (d128->bytes[15]>>2)&0x1f, in decimal128Show()
551 ((d128->bytes[15]&0x3)<<10)|(d128->bytes[14]<<2)| in decimal128Show()
552 (d128->bytes[13]>>6)); in decimal128Show()
556 sprintf(&buf[j], "%02x", d128->bytes[i]); in decimal128Show()