MCPcopy Create free account
hub / github.com/numpy/numpy / Dragon4_PrintFloat_IEEE_binary64

Function Dragon4_PrintFloat_IEEE_binary64

numpy/core/src/multiarray/dragon4.c:2391–2476  ·  view source on GitHub ↗

* IEEE binary64 floating-point format * * sign: 1 bit * exponent: 11 bits * mantissa: 52 bits */

Source from the content-addressed store, hash-verified

2389 * mantissa: 52 bits
2390 */
2391static npy_uint32
2392Dragon4_PrintFloat_IEEE_binary64(
2393 Dragon4_Scratch *scratch, npy_float64 *value, Dragon4_Options *opt)
2394{
2395 char *buffer = scratch->repr;
2396 const npy_uint32 bufferSize = sizeof(scratch->repr);
2397 BigInt *bigints = scratch->bigints;
2398
2399 union
2400 {
2401 npy_float64 floatingPoint;
2402 npy_uint64 integer;
2403 } floatUnion;
2404 npy_uint32 floatExponent, floatSign;
2405 npy_uint64 floatMantissa;
2406
2407 npy_uint64 mantissa;
2408 npy_int32 exponent;
2409 npy_uint32 mantissaBit;
2410 npy_bool hasUnequalMargins;
2411 char signbit = '\0';
2412
2413
2414 /* deconstruct the floating point value */
2415 floatUnion.floatingPoint = *value;
2416 floatMantissa = floatUnion.integer & bitmask_u64(52);
2417 floatExponent = (floatUnion.integer >> 52) & bitmask_u32(11);
2418 floatSign = floatUnion.integer >> 63;
2419
2420 /* output the sign */
2421 if (floatSign != 0) {
2422 signbit = '-';
2423 }
2424 else if (opt->sign) {
2425 signbit = '+';
2426 }
2427
2428 /* if this is a special value */
2429 if (floatExponent == bitmask_u32(11)) {
2430 return PrintInfNan(buffer, bufferSize, floatMantissa, 13, signbit);
2431 }
2432 /* else this is a number */
2433
2434 /* factor the value into its parts */
2435 if (floatExponent != 0) {
2436 /*
2437 * normal
2438 * The floating point equation is:
2439 * value = (1 + mantissa/2^52) * 2 ^ (exponent-1023)
2440 * We convert the integer equation by factoring a 2^52 out of the
2441 * exponent
2442 * value = (1 + mantissa/2^52) * 2^52 * 2 ^ (exponent-1023-52)
2443 * value = (2^52 + mantissa) * 2 ^ (exponent-1023-52)
2444 * Because of the implied 1 in front of the mantissa we have 53 bits of
2445 * precision.
2446 * m = (2^52 + mantissa)
2447 * e = (exponent-1023+1-53)
2448 */

Callers

nothing calls this directly

Calls 6

bitmask_u64Function · 0.85
bitmask_u32Function · 0.85
PrintInfNanFunction · 0.85
LogBase2_64Function · 0.85
BigInt_Set_uint64Function · 0.85
Format_floatbitsFunction · 0.85

Tested by

no test coverage detected