* Outputs the positive number with positional notation: ddddd.dddd * The output is always NUL terminated and the output length (not including the * NUL) is returned. * * Arguments: * buffer - buffer to output into * bufferSize - maximum characters that can be printed to buffer * mantissa - value significand * exponent - value exponent in base 2 * signbit - value of the sign
| 1637 | * See Dragon4_Options for description of remaining arguments. |
| 1638 | */ |
| 1639 | static npy_uint32 |
| 1640 | FormatPositional(char *buffer, npy_uint32 bufferSize, BigInt *mantissa, |
| 1641 | npy_int32 exponent, char signbit, npy_uint32 mantissaBit, |
| 1642 | npy_bool hasUnequalMargins, DigitMode digit_mode, |
| 1643 | CutoffMode cutoff_mode, npy_int32 precision, |
| 1644 | npy_int32 min_digits, TrimMode trim_mode, |
| 1645 | npy_int32 digits_left, npy_int32 digits_right) |
| 1646 | { |
| 1647 | npy_int32 printExponent; |
| 1648 | npy_int32 numDigits, numWholeDigits=0, has_sign=0; |
| 1649 | npy_int32 add_digits; |
| 1650 | |
| 1651 | npy_int32 maxPrintLen = (npy_int32)bufferSize - 1, pos = 0; |
| 1652 | |
| 1653 | /* track the # of digits past the decimal point that have been printed */ |
| 1654 | npy_int32 numFractionDigits = 0, desiredFractionalDigits; |
| 1655 | |
| 1656 | DEBUG_ASSERT(bufferSize > 0); |
| 1657 | |
| 1658 | if (digit_mode != DigitMode_Unique) { |
| 1659 | DEBUG_ASSERT(precision >= 0); |
| 1660 | } |
| 1661 | |
| 1662 | if (signbit == '+' && pos < maxPrintLen) { |
| 1663 | buffer[pos++] = '+'; |
| 1664 | has_sign = 1; |
| 1665 | } |
| 1666 | else if (signbit == '-' && pos < maxPrintLen) { |
| 1667 | buffer[pos++] = '-'; |
| 1668 | has_sign = 1; |
| 1669 | } |
| 1670 | |
| 1671 | numDigits = Dragon4(mantissa, exponent, mantissaBit, hasUnequalMargins, |
| 1672 | digit_mode, cutoff_mode, precision, min_digits, |
| 1673 | buffer + has_sign, maxPrintLen - has_sign, |
| 1674 | &printExponent); |
| 1675 | |
| 1676 | DEBUG_ASSERT(numDigits > 0); |
| 1677 | DEBUG_ASSERT(numDigits <= bufferSize); |
| 1678 | |
| 1679 | /* if output has a whole number */ |
| 1680 | if (printExponent >= 0) { |
| 1681 | /* leave the whole number at the start of the buffer */ |
| 1682 | numWholeDigits = printExponent+1; |
| 1683 | if (numDigits <= numWholeDigits) { |
| 1684 | npy_int32 count = numWholeDigits - numDigits; |
| 1685 | pos += numDigits; |
| 1686 | |
| 1687 | /* don't overflow the buffer */ |
| 1688 | if (pos + count > maxPrintLen) { |
| 1689 | count = maxPrintLen - pos; |
| 1690 | } |
| 1691 | |
| 1692 | /* add trailing zeros up to the decimal point */ |
| 1693 | numDigits += count; |
| 1694 | for ( ; count > 0; count--) { |
| 1695 | buffer[pos++] = '0'; |
| 1696 | } |
no test coverage detected