diff options
author | Matti Picus <matti.picus@gmail.com> | 2022-01-06 09:17:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-06 09:17:17 +0200 |
commit | 25807ca1ce80fa7ba8bfda16ae792053223ad965 (patch) | |
tree | a0208acecb312e9a59fe6b94c18e105e220fe5ec /numpy | |
parent | e967f51d19576e10ac741ff664c34d1116f1fc58 (diff) | |
parent | bf9298f85a4b3d8948d6f8916ac40badc1209661 (diff) | |
download | numpy-25807ca1ce80fa7ba8bfda16ae792053223ad965.tar.gz |
Merge pull request #20678 from corneliusroemer/fix/remove-trailing-point
BUG: Remove trailing dec point in dragon4positional
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/dragon4.c | 13 | ||||
-rw-r--r-- | numpy/core/tests/test_scalarprint.py | 1 |
2 files changed, 11 insertions, 3 deletions
diff --git a/numpy/core/src/multiarray/dragon4.c b/numpy/core/src/multiarray/dragon4.c index ce0293615..5d245b106 100644 --- a/numpy/core/src/multiarray/dragon4.c +++ b/numpy/core/src/multiarray/dragon4.c @@ -1809,9 +1809,16 @@ FormatPositional(char *buffer, npy_uint32 bufferSize, BigInt *mantissa, pos--; numFractionDigits--; } - if (trim_mode == TrimMode_LeaveOneZero && buffer[pos-1] == '.') { - buffer[pos++] = '0'; - numFractionDigits++; + if (buffer[pos-1] == '.') { + /* in TrimMode_LeaveOneZero, add trailing 0 back */ + if (trim_mode == TrimMode_LeaveOneZero){ + buffer[pos++] = '0'; + numFractionDigits++; + } + /* in TrimMode_DptZeros, remove trailing decimal point */ + else if (trim_mode == TrimMode_DptZeros) { + pos--; + } } } diff --git a/numpy/core/tests/test_scalarprint.py b/numpy/core/tests/test_scalarprint.py index ee21d4aa5..4deb5a0a4 100644 --- a/numpy/core/tests/test_scalarprint.py +++ b/numpy/core/tests/test_scalarprint.py @@ -306,6 +306,7 @@ class TestRealScalars: assert_equal(fpos(tp('1.2'), unique=False, precision=4, trim='-'), "1.2" if tp != np.float16 else "1.2002") assert_equal(fpos(tp('1.'), trim='-'), "1") + assert_equal(fpos(tp('1.001'), precision=1, trim='-'), "1") @pytest.mark.skipif(not platform.machine().startswith("ppc64"), reason="only applies to ppc float128 values") |