Lines Matching refs:decNumber
9 /* The description and User's Guide ("The decNumber C Library") for */
10 /* this software is called decNumber.pdf. This document is */
46 /* header file, see the User's Guide section of the decNumber */
56 /* 2. The decNumber format which this library uses is optimized for */
89 /* 6. The decNumber format is not an exchangeable concrete */
182 #include "decNumber.h" /* base number library */
183 #include "decNumberLocal.h" /* decNumber local types, etc. */
242 #error decNumber.c: DECUSE64 must be 1 when DECDPUN>4
249 static decNumber * decAddOp(decNumber *, const decNumber *, const decNumber *,
252 static uInt decCheckMath(const decNumber *, decContext *, uInt *);
253 static void decApplyRound(decNumber *, decContext *, Int, uInt *);
254 static Int decCompare(const decNumber *lhs, const decNumber *rhs, Flag);
255 static decNumber * decCompareOp(decNumber *, const decNumber *,
256 const decNumber *, decContext *,
258 static void decCopyFit(decNumber *, const decNumber *, decContext *,
260 static decNumber * decDecap(decNumber *, Int);
261 static decNumber * decDivideOp(decNumber *, const decNumber *,
262 const decNumber *, decContext *, Flag, uInt *);
263 static decNumber * decExpOp(decNumberdecNumber *,
265 static void decFinalize(decNumber *, decContext *, Int *, uInt *);
267 static Int decGetInt(const decNumber *);
268 static decNumber * decLnOp(decNumber *, const decNumber *,
270 static decNumber * decMultiplyOp(decNumber *, const decNumber *,
271 const decNumber *, decContext *,
273 static decNumber * decNaNs(decNumber *, const decNumber *,
274 const decNumber *, decContext *, uInt *);
275 static decNumber * decQuantizeOp(decNumber *, const decNumber *,
276 const decNumber *, decContext *, Flag,
279 static void decSetCoeff(decNumber *, decContext *, const Unit *,
281 static void decSetMaxValue(decNumber *, decContext *);
282 static void decSetOverflow(decNumber *, decContext *, uInt *);
283 static void decSetSubnormal(decNumber *, decContext *, Int *, uInt *);
286 static void decStatus(decNumber *, uInt, decContext *);
287 static void decToString(const decNumber *, char[], Flag);
288 static decNumber * decTrim(decNumber *, decContext *, Flag, Flag, Int *);
297 static void decFinish(decNumber *, decContext *, Int *, uInt *);
298 static decNumber * decRoundOperand(const decNumber *, decContext *, uInt *);
330 /* Optional checking routines. Enabling these means that decNumber */
338 #define DECUNRESU ((decNumber *)(void *)0xffffffff)
339 #define DECUNUSED ((const decNumber *)(void *)0xffffffff)
341 static Flag decCheckOperands(decNumber *, const decNumber *,
342 const decNumber *, decContext *);
343 static Flag decCheckNumber(const decNumber *);
344 static void decCheckInexact(const decNumber *, decContext *);
349 void decNumberShow(const decNumber *); /* displays the components of a number */
360 /* dn is the decNumber to receive the integer */
366 U_CAPI decNumber * U_EXPORT2 uprv_decNumberFromInt32(decNumber *dn, Int in) {
379 U_CAPI decNumber * U_EXPORT2 uprv_decNumberFromUInt32(decNumber *dn, uInt uin) {
394 /* dn is the decNumber to convert */
396 /* returns the converted decNumber, or 0 if Invalid is set */
398 /* Invalid is set if the decNumber does not have exponent==0 or if */
401 U_CAPI Int U_EXPORT2 uprv_decNumberToInt32(const decNumber *dn, decContext *set) {
437 U_CAPI uInt U_EXPORT2 uprv_decNumberToUInt32(const decNumber *dn, decContext *set) {
473 /* dn is the decNumber to convert */
480 U_CAPI char * U_EXPORT2 uprv_decNumberToString(const decNumber *dn, char *string){
485 U_CAPI char * U_EXPORT2 uprv_decNumberToEngString(const decNumber *dn, char *string){
493 /* decNumberFromString -- convert string to decNumber */
510 U_CAPI decNumber * U_EXPORT2 uprv_decNumberFromString(decNumber *dn, const char chars[],
602 /* [NB: payload in a decNumber can be full length unless */
670 /* OK, the digits string is good. Assemble in the decNumber, or in */
672 if (d<=set->digits) res=dn->lsu; /* fits into supplied decNumber */
759 U_CAPI decNumber * U_EXPORT2 uprv_decNumberAbs(decNumber *res, const decNumber *rhs,
761 decNumber dzero; /* for 0 */
791 U_CAPI decNumber * U_EXPORT2 uprv_decNumberAdd(decNumber *res, const decNumber *lhs,
792 const decNumber *rhs, decContext *set) {
817 U_CAPI decNumber * U_EXPORT2 uprv_decNumberAnd(decNumber *res, const decNumber *lhs,
818 const decNumber *rhs, decContext *set) {
885 U_CAPI decNumber * U_EXPORT2 uprv_decNumberCompare(decNumber *res, const decNumber *lhs,
886 const decNumber *rhs, decContext *set) {
905 U_CAPI decNumber * U_EXPORT2 uprv_decNumberCompareSignal(decNumber *res, const decNumber *lhs,
906 const decNumber *rhs, decContext *set) {
926 U_CAPI decNumber * U_EXPORT2 uprv_decNumberCompareTotal(decNumber *res, const decNumber *lhs,
927 const decNumber *rhs, decContext *set) {
947 U_CAPI decNumber * U_EXPORT2 uprv_decNumberCompareTotalMag(decNumber *res, const decNumber *lhs,
948 const decNumber *rhs, decContext *set) {
951 decNumber bufa[D2N(DECBUFFER+1)];/* +1 in case DECBUFFER=0 */
952 decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
953 decNumber bufb[D2N(DECBUFFER+1)];
954 decNumber *allocbufb=NULL; /* -> allocated bufb, iff allocated */
955 decNumber *a, *b; /* temporary pointers */
965 needbytes=sizeof(decNumber)+(D2U(lhs->digits)-1)*sizeof(Unit);
967 allocbufa=(decNumber *)malloc(needbytes);
979 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
981 allocbufb=(decNumber *)malloc(needbytes);
1012 U_CAPI decNumber * U_EXPORT2 uprv_decNumberDivide(decNumber *res, const decNumber *lhs,
1013 const decNumber *rhs, decContext *set) {
1035 U_CAPI decNumber * U_EXPORT2 uprv_decNumberDivideInteger(decNumber *res, const decNumber *lhs,
1036 const decNumber *rhs, decContext *set) {
1068 U_CAPI decNumber * U_EXPORT2 uprv_decNumberExp(decNumber *res, const decNumber *rhs,
1072 decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
1124 U_CAPI decNumber * U_EXPORT2 uprv_decNumberFMA(decNumber *res, const decNumber *lhs,
1125 const decNumber *rhs, const decNumber *fhs,
1130 decNumber bufa[D2N(DECBUFFER*2+1)];
1131 decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
1132 decNumber *acc; /* accumulator pointer */
1133 decNumber dzero; /* work */
1156 /* set up decNumber space to receive the result of the multiply */
1158 needbytes=sizeof(decNumber)+(D2U(dcmul.digits)-1)*sizeof(Unit);
1160 allocbufa=(decNumber *)malloc(needbytes);
1215 U_CAPI decNumber * U_EXPORT2 uprv_decNumberInvert(decNumber *res, const decNumber *rhs,
1288 U_CAPI decNumber * U_EXPORT2 uprv_decNumberLn(decNumber *res, const decNumber *rhs,
1292 decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
1354 U_CAPI decNumber * U_EXPORT2 uprv_decNumberLogB(decNumber *res, const decNumber *rhs,
1414 U_CAPI decNumber * U_EXPORT2 uprv_decNumberLog10(decNumber *res, const decNumber *rhs,
1423 decNumber bufa[D2N(DECBUFFER+2)];
1424 decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
1425 decNumber *a=bufa; /* temporary a */
1426 decNumber bufb[D2N(DECBUFFER+2)];
1427 decNumber *allocbufb=NULL; /* -> allocated bufb, iff allocated */
1428 decNumber *b=bufb; /* temporary b */
1429 decNumber bufw[D2N(10)]; /* working 2-10 digit number */
1430 decNumber *w=bufw; /* .. */
1432 decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
1491 needbytes=sizeof(decNumber)+(D2U(p)-1)*sizeof(Unit);
1493 allocbufa=(decNumber *)malloc(needbytes);
1514 needbytes=sizeof(decNumber)+(D2U(p)-1)*sizeof(Unit);
1516 allocbufb=(decNumber *)malloc(needbytes);
1565 U_CAPI decNumber * U_EXPORT2 uprv_decNumberMax(decNumber *res, const decNumber *lhs,
1566 const decNumber *rhs, decContext *set) {
1588 U_CAPI decNumber * U_EXPORT2 uprv_decNumberMaxMag(decNumber *res, const decNumber *lhs,
1589 const decNumber *rhs, decContext *set) {
1611 U_CAPI decNumber * U_EXPORT2 uprv_decNumberMin(decNumber *res, const decNumber *lhs,
1612 const decNumber *rhs, decContext *set) {
1634 U_CAPI decNumber * U_EXPORT2 uprv_decNumberMinMag(decNumber *res, const decNumber *lhs,
1635 const decNumber *rhs, decContext *set) {
1659 U_CAPI decNumber * U_EXPORT2 uprv_decNumberMinus(decNumber *res, const decNumber *rhs,
1661 decNumber dzero;
1689 U_CAPI decNumber * U_EXPORT2 uprv_decNumberNextMinus(decNumber *res, const decNumber *rhs,
1691 decNumber dtiny; /* constant */
1725 U_CAPI decNumber * U_EXPORT2 uprv_decNumberNextPlus(decNumber *res, const decNumber *rhs,
1727 decNumber dtiny; /* constant */
1765 U_CAPI decNumber * U_EXPORT2 uprv_decNumberNextToward(decNumber *res, const decNumber *lhs,
1766 const decNumber *rhs, decContext *set) {
1767 decNumber dtiny; /* constant */
1833 U_CAPI decNumber * U_EXPORT2 uprv_decNumberOr(decNumber *res, const decNumber *lhs,
1834 const decNumber *rhs, decContext *set) {
1903 U_CAPI decNumber * U_EXPORT2 uprv_decNumberPlus(decNumber *res, const decNumber *rhs,
1905 decNumber dzero;
1933 U_CAPI decNumber * U_EXPORT2 uprv_decNumberMultiply(decNumber *res, const decNumber *lhs,
1934 const decNumber *rhs, decContext *set) {
1970 U_CAPI decNumber * U_EXPORT2 uprv_decNumberPower(decNumber *res, const decNumber *lhs,
1971 const decNumber *rhs, decContext *set) {
1973 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
1974 decNumber *allocrhs=NULL; /* .., rhs */
1976 decNumber *allocdac=NULL; /* -> allocated acc buffer, iff used */
1977 decNumber *allocinv=NULL; /* -> allocated 1/x buffer, iff used */
1993 decNumber dnOne; /* work value 1... */
1994 /* local accumulator buffer [a decNumber, with digits+elength+1 digits] */
1995 decNumber dacbuff[D2N(DECBUFFER+9)];
1996 decNumber *dac=dacbuff; /* -> result accumulator */
1998 decNumber invbuff[D2N(DECBUFFER+9)];
2161 needbytes=sizeof(decNumber)+(D2U(aset.digits)-1)*sizeof(Unit);
2164 allocdac=(decNumber *)malloc(needbytes);
2202 decNumber *inv=invbuff; /* asssume use fixed buffer */
2211 allocinv=(decNumber *)malloc(needbytes);
2315 U_CAPI decNumber * U_EXPORT2 uprv_decNumberQuantize(decNumber *res, const decNumber *lhs,
2316 const decNumber *rhs, decContext *set) {
2335 U_CAPI decNumber * U_EXPORT2 uprv_decNumberNormalize(decNumber *res, const decNumber *rhs,
2340 U_CAPI decNumber * U_EXPORT2 uprv_decNumberReduce(decNumber *res, const decNumber *rhs,
2343 decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
2404 U_CAPI decNumber * U_EXPORT2 uprv_decNumberRescale(decNumber *res, const decNumber *lhs,
2405 const decNumber *rhs, decContext *set) {
2424 U_CAPI decNumber * U_EXPORT2 uprv_decNumberRemainder(decNumber *res, const decNumber *lhs,
2425 const decNumber *rhs, decContext *set) {
2447 U_CAPI decNumber * U_EXPORT2 uprv_decNumberRemainderNear(decNumber *res, const decNumber *lhs,
2448 const decNumber *rhs, decContext *set) {
2483 U_CAPI decNumber * U_EXPORT2 uprv_decNumberRotate(decNumber *res, const decNumber *lhs,
2484 const decNumber *rhs, decContext *set) {
2604 U_CAPI decNumber * U_EXPORT2 uprv_decNumberSameQuantum(decNumber *res, const decNumber *lhs,
2605 const decNumber *rhs) {
2639 U_CAPI decNumber * U_EXPORT2 uprv_decNumberScaleB(decNumber *res, const decNumber *lhs,
2640 const decNumber *rhs, decContext *set) {
2696 U_CAPI decNumber * U_EXPORT2 uprv_decNumberShift(decNumber *res, const decNumber *lhs,
2697 const decNumber *rhs, decContext *set) {
2829 U_CAPI decNumber * U_EXPORT2 uprv_decNumberSquareRoot(decNumber *res, const decNumber *rhs,
2832 decNumber dzero; /* used for constant zero */
2844 decNumber *allocrhs=NULL; /* non-NULL if rounded rhs allocated */
2847 decNumber buff[D2N(DECBUFFER+1)];
2849 decNumber bufa[D2N(DECBUFFER+2)];
2851 decNumber bufb[D2N(DECBUFFER+2)];
2852 decNumber *allocbuff=NULL; /* -> allocated buff, iff allocated */
2853 decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
2854 decNumber *allocbufb=NULL; /* -> allocated bufb, iff allocated */
2855 decNumber *f=buff; /* reduced fraction */
2856 decNumber *a=bufa; /* approximation to result */
2857 decNumber *b=bufb; /* intermediate result */
2859 decNumber buft[D2N(3)];
2860 decNumber *t=buft; /* up-to-3-digit constant or work */
2922 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
2924 allocbuff=(decNumber *)malloc(needbytes);
2931 needbytes=sizeof(decNumber)+(D2U(maxp)-1)*sizeof(Unit);
2933 allocbufa=(decNumber *)malloc(needbytes);
2934 allocbufb=(decNumber *)malloc(needbytes);
3174 U_CAPI decNumber * U_EXPORT2 uprv_decNumberSubtract(decNumber *res, const decNumber *lhs,
3175 const decNumber *rhs, decContext *set) {
3207 U_CAPI decNumber * U_EXPORT2 uprv_decNumberToIntegralExact(decNumber *res, const decNumber *rhs,
3209 decNumber dn;
3237 U_CAPI decNumber * U_EXPORT2 uprv_decNumberToIntegralValue(decNumber *res, const decNumber *rhs,
3263 U_CAPI decNumber * U_EXPORT2 uprv_decNumberXor(decNumber *res, const decNumber *lhs,
3264 const decNumber *rhs, decContext *set) {
3323 /* decNumberClass -- return the decClass of a decNumber */
3324 /* dn -- the decNumber to test */
3328 enum decClass uprv_decNumberClass(const decNumber *dn, decContext *set) {
3373 /* dest is the target decNumber */
3374 /* src is the source decNumber */
3381 U_CAPI decNumber * U_EXPORT2 uprv_decNumberCopy(decNumber *dest, const decNumber *src) {
3421 U_CAPI decNumber * U_EXPORT2 uprv_decNumberCopyAbs(decNumber *res, const decNumber *rhs) {
3442 U_CAPI decNumber * U_EXPORT2 uprv_decNumberCopyNegate(decNumber *res, const decNumber *rhs) {
3463 U_CAPI decNumber * U_EXPORT2 uprv_decNumberCopySign(decNumber *res, const decNumber *lhs,
3464 const decNumber *rhs) {
3478 /* dn is the source decNumber */
3486 U_CAPI uByte * U_EXPORT2 uprv_decNumberGetBCD(const decNumber *dn, uByte *bcd) {
3510 /* dn is the target decNumber */
3520 U_CAPI decNumber * U_EXPORT2 uprv_decNumberSetBCD(decNumber *dn, const uByte *bcd, uInt n) {
3540 /* decNumberIsNormal -- test normality of a decNumber */
3541 /* dn is the decNumber to test */
3545 Int uprv_decNumberIsNormal(const decNumber *dn, decContext *set) {
3560 /* decNumberIsSubnormal -- test subnormality of a decNumber */
3561 /* dn is the decNumber to test */
3565 Int uprv_decNumberIsSubnormal(const decNumber *dn, decContext *set) {
3589 U_CAPI decNumber * U_EXPORT2 uprv_decNumberTrim(decNumber *dn) {
3617 U_CAPI decNumber * U_EXPORT2 uprv_decNumberZero(decNumber *dn) {
3650 static void decToString(const decNumber *dn, char *string, Flag eng) {
3832 static decNumber * decAddOp(decNumber *res, const decNumber *lhs,
3833 const decNumber *rhs, decContext *set,
3836 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
3837 decNumber *allocrhs=NULL; /* .., rhs */
4020 const decNumber *t;
4248 static decNumber * decDivideOp(decNumber *res,
4249 const decNumber *lhs, const decNumber *rhs,
4252 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
4253 decNumber *allocrhs=NULL; /* .., rhs */
4868 static decNumber * decMultiplyOp(decNumber *res, const decNumber *lhs,
4869 const decNumber *rhs, decContext *set,
4925 decNumber *alloclhs=NULL; /* -> allocated buffer, iff allocated */
4926 decNumber *allocrhs=NULL; /* -> allocated buffer, iff allocated */
4955 const decNumber *hold=lhs;
5150 /* possibly with a leading zero unit; build the decNumber from */
5228 /* in the spirit of other decNumber operators, the input to be more */
5256 /* care, but the full decNumber range seems very hard within the */
5262 decNumber * decExpOp(decNumber *res, const decNumber *rhs,
5269 const decNumber *x=rhs; /* (may point to safe copy later) */
5276 decNumber bufr[D2N(DECBUFFER*2+1)];
5277 decNumber *allocrhs=NULL; /* non-NULL if rhs buffer allocated */
5284 decNumber buft[D2N(DECBUFFER*2+9+1)];
5285 decNumber *allocbuft=NULL; /* -> allocated buft, iff allocated */
5286 decNumber *t=buft; /* term */
5288 decNumber bufa[D2N(DECBUFFER*4+18+1)];
5289 decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
5290 decNumber *a=bufa; /* accumulator */
5291 /* decNumber for the divisor term; this needs at most 9 digits */
5293 decNumber bufd[D2N(16)];
5294 decNumber *d=bufd; /* divisor */
5295 decNumber numone; /* constant 1 */
5323 /* decNumber d for it (reused as the divisor, etc., below); its */
5395 decNumber *newrhs=bufr; /* assume will fit on stack */
5396 needbytes=sizeof(decNumber)+(D2U(rhs->digits)-1)*sizeof(Unit);
5398 allocrhs=(decNumber *)malloc(needbytes);
5428 needbytes=sizeof(decNumber)+(D2U(p*2)-1)*sizeof(Unit);
5430 allocbufa=(decNumber *)malloc(needbytes);
5440 needbytes=sizeof(decNumber)+(D2U(p+2)-1)*sizeof(Unit);
5442 allocbuft=(decNumber *)malloc(needbytes);
5626 decNumber * decLnOp(decNumber *res, const decNumber *rhs,
5638 decNumber bufa[D2N(DECBUFFER+12)];
5639 decNumber *allocbufa=NULL; /* -> allocated bufa, iff allocated */
5640 decNumber *a=bufa; /* accumulator/work */
5641 decNumber bufb[D2N(DECBUFFER*2+2)];
5642 decNumber *allocbufb=NULL; /* -> allocated bufa, iff allocated */
5643 decNumber *b=bufb; /* adjustment/work */
5645 decNumber numone; /* constant 1 */
5646 decNumber cmp; /* work */
5709 needbytes=sizeof(decNumber)+(D2U(MAXI(p,16))-1)*sizeof(Unit);
5711 allocbufa=(decNumber *)malloc(needbytes);
5718 needbytes=sizeof(decNumber)+(D2U(MAXI(pp,16))-1)*sizeof(Unit);
5720 allocbufb=(decNumber *)malloc(needbytes);
5873 static decNumber * decQuantizeOp(decNumber *res, const decNumber *lhs,
5874 const decNumber *rhs, decContext *set,
5877 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
5878 decNumber *allocrhs=NULL; /* .., rhs */
5880 const decNumber *inrhs=rhs; /* save original rhs */
6046 static decNumber * decCompareOp(decNumber *res, const decNumber *lhs,
6047 const decNumber *rhs, decContext *set,
6050 decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */
6051 decNumber *allocrhs=NULL; /* .., rhs */
6157 const decNumber *choice;
6204 /* Arg1 is A, a decNumber which is not a NaN */
6205 /* Arg2 is B, a decNumber which is not a NaN */
6211 static Int decCompare(const decNumber *lhs, const decNumber *rhs,
6246 const decNumber *temp=lhs;
6633 static decNumber * decTrim(decNumber *dn, decContext *set, Flag all,
6838 /* returns an allocated decNumber with the rounded result. */
6843 /* Instead, return an allocated decNumber, rounded as required. */
6849 static decNumber *decRoundOperand(const decNumber *dn, decContext *set,
6851 decNumber *res; /* result structure */
6855 decNumber, big enough for the */
6857 res=(decNumber *)malloc(sizeof(decNumber)
6876 /* dest is the target decNumber */
6877 /* src is the source decNumber */
6885 static void decCopyFit(decNumber *dest, const decNumber *src,
6931 static void decSetCoeff(decNumber *dn, decContext *set, const Unit *lsu,
7113 static void decApplyRound(decNumber *dn, decContext *set, Int residue,
7282 static void decFinish(decNumber *dn, decContext *set, Int *residue,
7317 static void decFinalize(decNumber *dn, decContext *set, Int *residue,
7330 decNumber nmin;
7391 static void decSetOverflow(decNumber *dn, decContext *set, uInt *status) {
7437 static void decSetMaxValue(decNumber *dn, decContext *set) {
7471 static void decSetSubnormal(decNumber *dn, decContext *set, Int *residue,
7557 decNumber *rhs, decContext *set,
7581 /* This checks and gets a whole number from the input decNumber. */
7585 static Int decGetInt(const decNumber *dn) {
7674 static decNumber *decDecap(decNumber *dn, Int drop) {
7733 static decNumber * decNaNs(decNumber *res, const decNumber *lhs,
7734 const decNumber *rhs, decContext *set,
7784 static void decStatus(decNumber *dn, uInt status, decContext *set) {
7856 void uprv_decNumberShow(const decNumber *dn) {
7953 static Flag decCheckOperands(decNumber *res, const decNumber *lhs,
7954 const decNumber *rhs, decContext *set) {
7999 static Flag decCheckNumber(const decNumber *dn) {
8008 printf("Reference to decNumber is NULL.\n");
8100 static void decCheckInexact(const decNumber *dn, decContext *set) {