Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-127937: convert decimal module to use import API for ints (PEP 757)#127925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 35 commits intopython:mainfromskirpichev:long_export-decimal
Jan 24, 2025
Merged
Changes from1 commit
Commits
Show all changes
35 commits
Select commitHold shift + click to select a range
80f1a04
gh-102471: convert decimal module to use PyLongWriter API (PEP 757)
skirpichevJul 6, 2024
c13b7d2
+ news
skirpichevDec 14, 2024
589f926
Apply suggestions from code review
skirpichevDec 14, 2024
f27adef
Merge branch 'master' into long_export-decimal
skirpichevDec 14, 2024
6669b89
+ adapt dec_from_long() to use PEP 757
skirpichevDec 14, 2024
05ec274
Merge branch 'master' into long_export-decimal
skirpichevDec 16, 2024
6e46bc1
Don't use PyLong_GetNativeLayout()
skirpichevDec 16, 2024
7f0061f
Address review:
skirpichevDec 16, 2024
bae0234
Apply suggestions from code review
skirpichevDec 16, 2024
4e0460c
address review: don't use digit type
skirpichevDec 16, 2024
87ded2e
+ forgot (char*) cast
skirpichevDec 16, 2024
541441e
Apply Serhiy suggestion
skirpichevDec 16, 2024
6ab20f1
add asserts
skirpichevDec 17, 2024
83471fd
speed up export
skirpichevDec 17, 2024
cb169f7
Apply suggestions from code review
skirpichevDec 17, 2024
0ea0d59
Merge branch 'master' into long_export-decimal
skirpichevDec 19, 2024
61e76d2
use PyLong_GetNativeLayout() to query layout
skirpichevDec 19, 2024
90bafc1
+ comment
skirpichevDec 19, 2024
c117956
Apply suggestions from code review
skirpichevDec 19, 2024
7b97855
address review:
skirpichevDec 20, 2024
7e0e9a9
Update Misc/NEWS.d/next/C_API/2024-12-14-03-40-15.gh-issue-127925.FF7…
skirpichevDec 22, 2024
fec6666
Merge branch 'master' into long_export-decimal
skirpichevDec 26, 2024
5a00ee2
set all digits to 0
skirpichevDec 26, 2024
37ec841
Merge branch 'master' into long_export-decimal
skirpichevJan 6, 2025
d4728c4
Merge branch 'master' into long_export-decimal
skirpichevJan 6, 2025
f6a4afb
+ cleanup, add asserts
skirpichevJan 7, 2025
4b07189
Merge branch 'master' into long_export-decimal
skirpichevJan 7, 2025
4db7917
Merge branch 'master' into long_export-decimal
skirpichevJan 7, 2025
0fec6e1
address review
skirpichevJan 7, 2025
59636f9
address review
skirpichevJan 7, 2025
b8bf49f
Update Modules/_decimal/_decimal.c
skirpichevJan 8, 2025
a8189e6
Update Modules/_decimal/_decimal.c
skirpichevJan 12, 2025
3854262
Merge branch 'master' into long_export-decimal
skirpichevJan 24, 2025
336e881
use temporary buffer of digits, tmp_digits
skirpichevJan 24, 2025
e658f2b
address review: comment
skirpichevJan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Don't use PyLong_GetNativeLayout()
  • Loading branch information
@skirpichev
skirpichev committedDec 16, 2024
commit6e46bc1de119a5759c68401a05dd167ba5300cc7
28 changes: 10 additions & 18 deletionsModules/_decimal/_decimal.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2335,24 +2335,18 @@ dec_from_long(decimal_state *state, PyTypeObject *type, PyObject *v,
return NULL;
}
if (export_long.digits) {
const PyLongLayout *layout = PyLong_GetNativeLayout();
const uint8_t bpd = layout->bits_per_digit;
const uint8_t sign = export_long.negative ? MPD_NEG : MPD_POS;
const Py_ssize_t len = export_long.ndigits;

if (bpd == 30) {
mpd_qimport_u32(MPD(dec), export_long.digits, len, sign,
1 << bpd, ctx, status);
}
else if (bpd == 15) {
mpd_qimport_u16(MPD(dec), export_long.digits, len, sign,
1 << bpd, ctx, status);
}
else {
PyLong_FreeExport(&export_long);
Py_DECREF(dec);
return NULL;
}
#if PYLONG_BITS_IN_DIGIT == 30
mpd_qimport_u32(MPD(dec), export_long.digits, len, sign,
PyLong_BASE, ctx, status);
#elif PYLONG_BITS_IN_DIGIT == 15
mpd_qimport_u16(MPD(dec), export_long.digits, len, sign,
PyLong_BASE, ctx, status);
#else
#error "PYLONG_BITS_IN_DIGIT should be 15 or 30"
#endif
PyLong_FreeExport(&export_long);
}
else {
Expand DownExpand Up@@ -3648,7 +3642,6 @@ dec_as_long(PyObject *dec, PyObject *context, int round)
mpd_t *x;
mpd_context_t workctx;
uint32_t status = 0;
const PyLongLayout *layout = PyLong_GetNativeLayout();

if (mpd_isspecial(MPD(dec))) {
if (mpd_isnan(MPD(dec))) {
Expand DownExpand Up@@ -3683,8 +3676,7 @@ dec_as_long(PyObject *dec, PyObject *context, int round)
return PyLong_FromInt64(val);
}

const uint8_t bpd = layout->bits_per_digit;
n = (mpd_sizeinbase(x, 2) + bpd - 1) / bpd;
n = (mpd_sizeinbase(x, 2) + PyLong_SHIFT - 1)/PyLong_SHIFT;
PyLongWriter *writer = PyLongWriter_Create(mpd_isnegative(x), n,
(void**)&ob_digit);
/* mpd_sizeinbase can overestimate size by 1 digit, set it to zero. */
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

BTW, this looks as a bug in the mpdecimal. C.f. the GNU GMP, the mpz_sizeinbase docs says: "If base is a power of 2, the result is always exact".

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp