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

1 /* Decimal 32-bit format module for the decNumber C Library.
29 02110-1301, USA. */
31 /* ------------------------------------------------------------------ */
32 /* Decimal 32-bit format module */
33 /* ------------------------------------------------------------------ */
41 /* ------------------------------------------------------------------ */
66 /* ------------------------------------------------------------------ */
67 /* decimal32FromNumber -- convert decNumber to decimal32 */
82 /* ------------------------------------------------------------------ */
91 uInt targ=0; /* target 32-bit */ in decimal32FromNumber()
98 ae=dn->exponent+dn->digits-1; /* [0 if special] */ in decimal32FromNumber()
99 if (dn->digits>DECIMAL32_Pmax /* too many digits */ in decimal32FromNumber()
103 dc.round=set->round; /* use supplied rounding */ in decimal32FromNumber()
105 /* [this changes -0 to 0, so enforce the sign...] */ in decimal32FromNumber()
106 dw.bits|=dn->bits&DECNEG; in decimal32FromNumber()
111 if (dn->bits&DECSPECIAL) { /* a special value */ in decimal32FromNumber()
112 if (dn->bits&DECINF) targ=DECIMAL_Inf<<24; in decimal32FromNumber()
114 if ((*dn->lsu!=0 || dn->digits>1) /* non-zero coefficient */ in decimal32FromNumber()
115 && (dn->digits<DECIMAL32_Pmax)) { /* coefficient fits */ in decimal32FromNumber()
118 if (dn->bits&DECNAN) targ|=DECIMAL_NaN<<24; in decimal32FromNumber()
126 if (dn->exponent<-DECIMAL32_Bias) { in decimal32FromNumber()
131 exp=dn->exponent+DECIMAL32_Bias; /* bias exponent */ in decimal32FromNumber()
139 else { /* non-zero finite number */ in decimal32FromNumber()
144 exp=(uInt)(dn->exponent+DECIMAL32_Bias); /* bias exponent */ in decimal32FromNumber()
145 if (exp>DECIMAL32_Ehigh) { /* fold-down case */ in decimal32FromNumber()
146 pad=exp-DECIMAL32_Ehigh; in decimal32FromNumber()
153 targ=BIN2DPD[dn->lsu[0]]; in decimal32FromNumber()
154 if (dn->digits>3) targ|=(uInt)(BIN2DPD[dn->lsu[1]])<<10; in decimal32FromNumber()
155 msd=(dn->digits==7 ? dn->lsu[2] : 0); in decimal32FromNumber()
172 if (dn->bits&DECNEG) targ|=0x80000000; /* add sign bit */ in decimal32FromNumber()
175 pu=(uInt *)d32->bytes; /* overlay */ in decimal32FromNumber()
183 /* ------------------------------------------------------------------ */
184 /* decimal32ToNumber -- convert decimal32 to decNumber */
188 /* ------------------------------------------------------------------ */
193 uInt sour; /* source 32-bit */ in decimal32ToNumber()
197 pu=(const uInt *)d32->bytes; /* overlay */ in decimal32ToNumber()
203 if (sour&0x80000000) dn->bits=DECNEG; /* set sign if negative */ in decimal32ToNumber()
210 dn->bits|=DECINF; in decimal32ToNumber()
213 else if (sour&0x02000000) dn->bits|=DECSNAN; in decimal32ToNumber()
214 else dn->bits|=DECNAN; in decimal32ToNumber()
218 dn->exponent=(exp<<6)+((sour>>20)&0x3f)-DECIMAL32_Bias; /* unbiased */ in decimal32ToNumber()
223 if (msd) { /* non-zero msd */ in decimal32ToNumber()
237 /* ------------------------------------------------------------------ */
238 /* to-scientific-string -- conversion to numeric string */
239 /* to-engineering-string -- conversion to numeric string */
250 /* ------------------------------------------------------------------ */
269 uInt sour; /* source 32-bit */ in decimal32ToString()
272 pu=(const uInt *)d32->bytes; /* overlay */ in decimal32ToString()
276 if (((Int)sour)<0) *c++='-'; /* handle sign */ in decimal32ToString()
295 else exp=(exp<<6)+((sour>>20)&0x3f)-DECIMAL32_Bias; /* unbiased */ in decimal32ToString()
299 if (msd) *c++='0'+(char)msd; /* non-zero most significant digit */ in decimal32ToString()
302 /* decoded to binary and then to a 4-char sequence by table lookup; */ in decimal32ToString()
303 /* the 4-chars are a 1-char length (significant digits, except 000 */ in decimal32ToString()
304 /* has length 0). This allows us to left-align the first declet */ in decimal32ToString()
305 /* with non-zero content, then remaining ones are full 3-char */ in decimal32ToString()
306 /* length. We use fixed-length memcpys because variable-length */ in decimal32ToString()
307 /* causes a subroutine call in GCC. (These are length 4 for speed */ in decimal32ToString()
311 else if (*u) {memcpy(c, u+4-*u, 4); c+=*u;} in decimal32ToString()
318 if (c==cstart) *c++='0'; /* all zeros -- make 0 */ in decimal32ToString()
320 if (exp==0) { /* integer or NaN case -- easy */ in decimal32ToString()
325 /* non-0 exponent */ in decimal32ToString()
327 pre=c-cstart+exp; in decimal32ToString()
328 /* [here, pre-exp is the digits count (==1 for zero)] */ in decimal32ToString()
329 if (exp>0 || pre<-5) { /* need exponential form */ in decimal32ToString()
330 e=pre-1; /* calculate E value */ in decimal32ToString()
335 s=c-1; /* source (LSD) */ in decimal32ToString()
340 for (; s>=dotat; s--, t--) *t=*s; /* open the gap; leave t at gap */ in decimal32ToString()
342 c++; /* length increased by one */ in decimal32ToString()
345 /* finally add the E-part, if needed; it will never be 0, and has */ in decimal32ToString()
346 /* a maximum length of 3 digits (E-101 case) */ in decimal32ToString()
351 *(c-1)='-'; /* oops, need '-' */ in decimal32ToString()
352 e=-e; /* uInt, please */ in decimal32ToString()
354 u=&BIN2CHAR[e*4]; /* -> length byte */ in decimal32ToString()
355 memcpy(c, u+4-*u, 4); /* copy fixed 4 characters [is safe] */ in decimal32ToString()
363 /* -5<=pre<=0: here for plain 0.ddd or 0.000ddd forms (can never have E) */ in decimal32ToString()
364 t=c+1-pre; in decimal32ToString()
366 for (; s>=cstart; s--, t--) *t=*s; /* shift whole coefficient right */ in decimal32ToString()
375 /* ------------------------------------------------------------------ */
376 /* to-number -- conversion from numeric string */
389 /* ------------------------------------------------------------------ */
396 dc.round=set->round; /* use supplied rounding */ in decimal32FromString()
406 /* ------------------------------------------------------------------ */
407 /* decimal32IsCanonical -- test whether encoding is canonical */
411 /* ------------------------------------------------------------------ */
422 /* ------------------------------------------------------------------ */
423 /* decimal32Canonical -- copy an encoding, ensuring it is canonical */
428 /* ------------------------------------------------------------------ */
441 decimal32 is in network byte order (big-endian) */
443 #define decimal32Sign(d) ((unsigned)(d)->bytes[0]>>7)
446 #define decimal32Comb(d) (((d)->bytes[0] & 0x7c)>>2)
449 #define decimal32ExpCon(d) ((((d)->bytes[0] & 0x03)<<4) \
450 | ((unsigned)(d)->bytes[1]>>4))
454 (d)->bytes[0]|=((unsigned)(b)<<7);}
460 (d)->bytes[0]|=(uint8_t)((e)>>4); \
461 (d)->bytes[1]|=(uint8_t)(((e)&0x0F)<<4);}
463 /* ------------------------------------------------------------------ */
464 /* decimal32Show -- display a decimal32 in hexadecimal [debug aid] */
465 /* d32 -- the number to show */
466 /* ------------------------------------------------------------------ */
467 /* Also shows sign/cob/expconfields extracted - valid bigendian only */
474 sprintf(&buf[j], "%02x", d32->bytes[3-i]); in decimal32Show()
477 d32->bytes[3]>>7, (d32->bytes[3]>>2)&0x1f, in decimal32Show()
478 ((d32->bytes[3]&0x3)<<4)| (d32->bytes[2]>>4)); in decimal32Show()
482 sprintf(&buf[j], "%02x", d32->bytes[i]); in decimal32Show()