This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients mark.dickinson, pitrou, serhiy.storchaka, vstinner, yselivanov
Date 2016-02-09.16:35:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1455035740.37.0.122502784336.issue26289@psf.upfronthosting.co.za>
In-reply-to
Content
Just for the record, there's a less-branchy analog of the floor division code I suggested for modulo. In Python-land, it looks like this:

def propermod(a, b):
    # mimic the C setup
    assert a != 0 and b != 0
    left = abs(a)
    size_a = -1 if a < 0 else 1
    right = abs(b)
    size_b = -1 if b < 0 else 1

    # Compute mod: only one branch needed.
    mod = left % right if size_a == size_b else right - 1 - (left - 1) % right
    return mod * size_b

# Verify that we get the same results as the regular mod.
for n in range(-100, 100):
    if n == 0:
        continue
    for d in range(-100, 100):
        if d == 0:
            continue
        assert propermod(n, d) == n % d

It may well not have any significant effect here, though.
History
Date User Action Args
2016-02-09 16:35:40mark.dickinsonsetrecipients: + mark.dickinson, pitrou, vstinner, serhiy.storchaka, yselivanov
2016-02-09 16:35:40mark.dickinsonsetmessageid: <1455035740.37.0.122502784336.issue26289@psf.upfronthosting.co.za>
2016-02-09 16:35:40mark.dickinsonlinkissue26289 messages
2016-02-09 16:35:40mark.dickinsoncreate