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

Consider adding public PyLong_FlipSign() function #120446

Closed as not planned
Closed as not planned
Labels
@skirpichev

Description

@skirpichev

Feature or enhancement

Proposal:

Currently there is only a slow way (i.e.PyNumber_Negative()) to invert the sign of a big integer. Direct manipulation of the sign value is available only via private function, e.g._PyLong_SetSignAndDigitCount():
https://github.com/aleaxit/gmpy/blob/1c0d4f38d4f1093df0e9460d82e4331d3d3946b6/src/gmpy2_convert_gmp.c#L153

I propose this interface:

intPyLong_FlipSign(PyObject*obj);

For small integers it will fallback toPyLong_FromLong() (like_PyLong_Negate() does), for the rest - just_PyLong_FlipSign() to change sign in place.

Alternatively, we could just expose a direct wrapper of_PyLong_FlipSign() and warn users to not use this function for small ints (that doesn't make sense for me anyway).

In both variants, on success - flip the sign ofobj and return 0. On failure - return -1 with exception set. Shouldn't fail on PyLongObject or it's subtype.

I'll work on a patch if this proposal does make sense.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp