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

Function FormatScientific

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

* Outputs the positive number with scientific notation: d.dddde[sign]ddd * 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 th

Source from the content-addressed store, hash-verified

1882 * See Dragon4_Options for description of remaining arguments.
1883 */
1884static npy_uint32
1885FormatScientific (char *buffer, npy_uint32 bufferSize, BigInt *mantissa,
1886 npy_int32 exponent, char signbit, npy_uint32 mantissaBit,
1887 npy_bool hasUnequalMargins, DigitMode digit_mode,
1888 npy_int32 precision, npy_int32 min_digits, TrimMode trim_mode,
1889 npy_int32 digits_left, npy_int32 exp_digits)
1890{
1891 npy_int32 printExponent;
1892 npy_int32 numDigits;
1893 char *pCurOut;
1894 npy_int32 numFractionDigits;
1895 npy_int32 leftchars;
1896 npy_int32 add_digits;
1897
1898 if (digit_mode != DigitMode_Unique) {
1899 DEBUG_ASSERT(precision >= 0);
1900 }
1901
1902 DEBUG_ASSERT(bufferSize > 0);
1903
1904 pCurOut = buffer;
1905
1906 /* add any whitespace padding to left side */
1907 leftchars = 1 + (signbit == '-' || signbit == '+');
1908 if (digits_left > leftchars) {
1909 int i;
1910 for (i = 0; i < digits_left - leftchars && bufferSize > 1; i++) {
1911 *pCurOut = ' ';
1912 pCurOut++;
1913 --bufferSize;
1914 }
1915 }
1916
1917 if (signbit == '+' && bufferSize > 1) {
1918 *pCurOut = '+';
1919 pCurOut++;
1920 --bufferSize;
1921 }
1922 else if (signbit == '-' && bufferSize > 1) {
1923 *pCurOut = '-';
1924 pCurOut++;
1925 --bufferSize;
1926 }
1927
1928 numDigits = Dragon4(mantissa, exponent, mantissaBit, hasUnequalMargins,
1929 digit_mode, CutoffMode_TotalLength,
1930 precision < 0 ? -1 : precision + 1,
1931 min_digits < 0 ? -1 : min_digits + 1,
1932 pCurOut, bufferSize, &printExponent);
1933
1934 DEBUG_ASSERT(numDigits > 0);
1935 DEBUG_ASSERT(numDigits <= bufferSize);
1936
1937 /* keep the whole number as the first digit */
1938 if (bufferSize > 1) {
1939 pCurOut += 1;
1940 bufferSize -= 1;
1941 }

Callers 1

Format_floatbitsFunction · 0.85

Calls 1

Dragon4Function · 0.85

Tested by

no test coverage detected