MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / xsum_small_round

Function xsum_small_round

xs/sources/xsum.c:1128–1471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1126 represents should not change. */
1127
1128xsum_flt xsum_small_round (xsum_small_accumulator *restrict sacc)
1129{
1130 xsum_int ivalue;
1131 xsum_schunk lower;
1132 int i, j, e, more;
1133 xsum_int intv;
1134 double fltv;
1135
1136 if (xsum_debug) c_printf("\nROUNDING SMALL ACCUMULATOR\n");
1137
1138 /* See if we have a NaN from one of the numbers being a NaN, in
1139 which case we return the NaN with largest payload, or an infinite
1140 result (+Inf, -Inf, or a NaN if both +Inf and -Inf occurred).
1141 Note that we do NOT return NaN if we have both an infinite number
1142 and a sum of other numbers that overflows with opposite sign,
1143 since there is no real ambiguity regarding the sign in such a case. */
1144
1145 if (sacc->NaN != 0)
1146 { COPY64(fltv, sacc->NaN);
1147 return fltv;
1148 }
1149
1150 if (sacc->Inf != 0)
1151 { COPY64 (fltv, sacc->Inf);
1152 return fltv;
1153 }
1154
1155 /* If none of the numbers summed were infinite or NaN, we proceed to
1156 propagate carries, as a preliminary to finding the magnitude of
1157 the sum. This also ensures that the sign of the result can be
1158 determined from the uppermost non-zero chunk.
1159
1160 We also find the index, i, of this uppermost non-zero chunk, as
1161 the value returned by xsum_carry_propagate, and set ivalue to
1162 sacc->chunk[i]. Note that ivalue will not be 0 or -1, unless
1163 i is 0 (the lowest chunk), in which case it will be handled by
1164 the code for denormalized numbers. */
1165
1166 i = xsum_carry_propagate(sacc);
1167
1168 if (xsum_debug) xsum_small_display(sacc);
1169
1170 ivalue = sacc->chunk[i];
1171
1172 /* Handle a possible denormalized number, including zero. */
1173
1174 if (i <= 1)
1175 {
1176 /* Check for zero value, in which case we can return immediately. */
1177
1178 if (ivalue == 0)
1179 { return 0.0;
1180 }
1181
1182 /* Check if it is actually a denormalized number. It always is if only
1183 the lowest chunk is non-zero. If the highest non-zero chunk is the
1184 next-to-lowest, we check the magnitude of the absolute value.
1185 Note that the real exponent is 1 (not 0), so we need to shift right

Callers 3

xsum_large_roundFunction · 0.85
xsum_small_div_unsignedFunction · 0.85
fx_Math_sumPreciseFunction · 0.85

Calls 2

xsum_carry_propagateFunction · 0.85
xsum_small_displayFunction · 0.85

Tested by

no test coverage detected