Skip to content

PCG jump incorrectly emulates uint128 shift #20048

@runewalsh

Description

@runewalsh

In random/src/pcg64/pcg64.c, uint128 version (PCG_EMULATED_128BIT_MATH disabled) performs:

delta /= 2;

uint64+64 version (PCG_EMULATED_128BIT_MATH enabled) emulates it with manual delta >>= 1ing:

delta.low >>= 1;
delta.low += delta.high & 1;
delta.high >>= 1;

This is obviously incorrect and will screw up jumps by 264 or more (those with delta.high != 0). Must be rather:

delta.low = (delta.low >> 1) | (delta.high << 63);
delta.high >>= 1;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions