MCPcopy Create free account
hub / github.com/ablab/spades / convertToSignExtendedInteger

Method convertToSignExtendedInteger

ext/src/llvm/APFloat.cpp:2260–2362  ·  view source on GitHub ↗

Convert a floating point number to an integer according to the rounding mode. If the rounded integer value is out of range this returns an invalid operation exception and the contents of the destination parts are unspecified. If the rounded value is in range but the floating point number is not the exact integer, the C standard doesn't require an inexact exception to be raised. I

Source from the content-addressed store, hash-verified

2258 Note that for conversions to integer type the C standard requires
2259 round-to-zero to always be used. */
2260IEEEFloat::opStatus IEEEFloat::convertToSignExtendedInteger(
2261 MutableArrayRef<integerPart> parts, unsigned int width, bool isSigned,
2262 roundingMode rounding_mode, bool *isExact) const {
2263 lostFraction lost_fraction;
2264 const integerPart *src;
2265 unsigned int dstPartsCount, truncatedBits;
2266
2267 *isExact = false;
2268
2269 /* Handle the three special cases first. */
2270 if (category == fcInfinity || category == fcNaN)
2271 return opInvalidOp;
2272
2273 dstPartsCount = partCountForBits(width);
2274 assert(dstPartsCount <= parts.size() && "Integer too big");
2275
2276 if (category == fcZero) {
2277 APInt::tcSet(parts.data(), 0, dstPartsCount);
2278 // Negative zero can't be represented as an int.
2279 *isExact = !sign;
2280 return opOK;
2281 }
2282
2283 src = significandParts();
2284
2285 /* Step 1: place our absolute value, with any fraction truncated, in
2286 the destination. */
2287 if (exponent < 0) {
2288 /* Our absolute value is less than one; truncate everything. */
2289 APInt::tcSet(parts.data(), 0, dstPartsCount);
2290 /* For exponent -1 the integer bit represents .5, look at that.
2291 For smaller exponents leftmost truncated bit is 0. */
2292 truncatedBits = semantics->precision -1U - exponent;
2293 } else {
2294 /* We want the most significant (exponent + 1) bits; the rest are
2295 truncated. */
2296 unsigned int bits = exponent + 1U;
2297
2298 /* Hopelessly large in magnitude? */
2299 if (bits > width)
2300 return opInvalidOp;
2301
2302 if (bits < semantics->precision) {
2303 /* We truncate (semantics->precision - bits) bits. */
2304 truncatedBits = semantics->precision - bits;
2305 APInt::tcExtract(parts.data(), dstPartsCount, src, bits, truncatedBits);
2306 } else {
2307 /* We want at least as many bits as are available. */
2308 APInt::tcExtract(parts.data(), dstPartsCount, src, semantics->precision,
2309 0);
2310 APInt::tcShiftLeft(parts.data(), dstPartsCount,
2311 bits - semantics->precision);
2312 truncatedBits = 0;
2313 }
2314 }
2315
2316 /* Step 2: work out any lost fraction, and increment the absolute
2317 value if we would round away from zero. */

Callers

nothing calls this directly

Calls 6

partCountForBitsFunction · 0.85
assertClass · 0.85
tcIncrementFunction · 0.85
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected