MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / decFloatAdd

Function decFloatAdd

extern/decNumber/decBasic.c:1102–1568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1100#endif
1101
1102decFloat * decFloatAdd(decFloat *result,
1103 const decFloat *dfl, const decFloat *dfr,
1104 decContext *set) {
1105 bcdnum num; // for final conversion
1106 Int bexpl, bexpr; // left and right biased exponents
1107 uByte *ub, *us, *ut; // work
1108 uInt uiwork; // for macros
1109 #if QUAD
1110 uShort uswork; // ..
1111 #endif
1112
1113 uInt sourhil, sourhir; // top words from source decFloats
1114 // [valid only through end of
1115 // fastpath code -- before swap]
1116 uInt diffsign; // non-zero if signs differ
1117 uInt carry; // carry: 0 or 1 before add loop
1118 Int overlap; // coefficient overlap (if full)
1119 Int summ; // sum of the MSDs
1120 // the following buffers hold coefficients with various alignments
1121 // (see commentary and diagrams below)
1122 uByte acc[4+2+DECPMAX*3+8];
1123 uByte buf[4+2+DECPMAX*2];
1124 uByte *umsd, *ulsd; // local MSD and LSD pointers
1125
1126 #if DECLITEND
1127 #define CARRYPAT 0x01000000 // carry=1 pattern
1128 #else
1129 #define CARRYPAT 0x00000001 // carry=1 pattern
1130 #endif
1131
1132 /* Start decoding the arguments */
1133 // The initial exponents are placed into the opposite Ints to
1134 // that which might be expected; there are two sets of data to
1135 // keep track of (each decFloat and the corresponding exponent),
1136 // and this scheme means that at the swap point (after comparing
1137 // exponents) only one pair of words needs to be swapped
1138 // whichever path is taken (thereby minimising worst-case path).
1139 // The calculated exponents will be nonsense when the arguments are
1140 // Special, but are not used in that path
1141 sourhil=DFWORD(dfl, 0); // LHS top word
1142 summ=DECTESTMSD[sourhil>>26]; // get first MSD for testing
1143 bexpr=DECCOMBEXP[sourhil>>26]; // get exponent high bits (in place)
1144 bexpr+=GETECON(dfl); // .. + continuation
1145
1146 sourhir=DFWORD(dfr, 0); // RHS top word
1147 summ+=DECTESTMSD[sourhir>>26]; // sum MSDs for testing
1148 bexpl=DECCOMBEXP[sourhir>>26];
1149 bexpl+=GETECON(dfr);
1150
1151 // here bexpr has biased exponent from lhs, and vice versa
1152
1153 diffsign=(sourhil^sourhir)&DECFLOAT_Sign;
1154
1155 // now determine whether to take a fast path or the full-function
1156 // slow path. The slow path must be taken when:
1157 // -- both numbers are finite, and:
1158 // the exponents are different, or
1159 // the signs are different, or

Callers 3

decFloatNextMinusFunction · 0.85
decFloatNextPlusFunction · 0.85
decFloatSubtractFunction · 0.85

Calls 7

decInvalidFunction · 0.85
decInfinityFunction · 0.85
decCanonicalFunction · 0.85
decShowNumFunction · 0.85
decFloatShowFunction · 0.85
decNaNsFunction · 0.70
decFinalizeFunction · 0.70

Tested by

no test coverage detected