Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118330 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2852 invoked from network); 31 Jul 2022 15:53:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Jul 2022 15:53:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 43702180505 for ; Sun, 31 Jul 2022 10:52:25 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 31 Jul 2022 10:52:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1659289942; bh=d4K6Z32tqqe/UXdbh59Q4y05DORCr8LpAiv2Ezu8APo=; h=Date:Subject:To:References:From:In-Reply-To:From; b=ceIUIOx+89hOP+ebSXcwaJV0MnxwOrLaFlxfXsQMOdcMnY2UbXNCBX7dzHJoSxlSS Spcd/xmZSG5QmEz07Hq7wkFYNarsedYwzX/GJTHGJ+4UrkntVUrw6nq1cg9+7lc0vg xlk80TKnJ5LVC6K6mQdIssFVlQmEGbRJuOp1AsrH+NU7BtJwPoBvJG8mSoUHORv5EX +gqwc1nESOP8L8WdbYkW3gBGNWizkqBCBjf/h2gB378bxB5tqSM25bAbo+y4msGQZr HhrO7tRfkGKUxLlHPbctXCDQ+bI8IGX6eS2lF6yZexIIRcbB67Y2DPtBbhAqfThu+A 0Kl/VhBzFnrsA== Message-ID: Date: Sun, 31 Jul 2022 19:52:21 +0200 MIME-Version: 1.0 Content-Language: en-US To: Anton Smirnov , PHP Internals List References: <524dff3654286a804043c7c49dffe9c526d2114b.camel@sandfox.me> In-Reply-To: <524dff3654286a804043c7c49dffe9c526d2114b.camel@sandfox.me> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Negative values in PcgOneseq128XslRr64::jump($advance) From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 7/31/22 17:50, Anton Smirnov wrote: > I'm writing a polyfill for ext-random and I noticed a small weirdness. > PcgOneseq128XslRr64::jump() accepts negative $advance where it > automagically becomes unsigned positive. Yes, this is what happens when casting a negative signed integer to an unsigned integer. It will wrap around to the maximum positive number minus whatever the negative value was. > Does it make sense or maybe it's better to throw a ValueError there? No it doesn't, especially since: $a = $pcg->generate(); $pcg->jump(-1); // jumps back 2^64 - 1 steps in a 64-bit system var_dump($pcg->generate() === $a); // bool(false) The PCG state is 128 Bits, so a negative jump does not work as expected and thus should throw. Would you mind filing an issue in the tracker, so that it can be properly referenced (and thus you properly credited for this find)? https://github.com/php/php-src/issues Best regards Tim Düsterhus