Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:74235 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25341 invoked from network); 15 May 2014 19:10:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 May 2014 19:10:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@marc-bennewitz.de; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@marc-bennewitz.de; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain marc-bennewitz.de does not designate 80.237.132.171 as permitted sender) X-PHP-List-Original-Sender: php@marc-bennewitz.de X-Host-Fingerprint: 80.237.132.171 wp164.webpack.hosteurope.de Received: from [80.237.132.171] ([80.237.132.171:56039] helo=wp164.webpack.hosteurope.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 89/F1-14382-D1115735 for ; Thu, 15 May 2014 15:10:22 -0400 Received: from dslb-178-005-224-019.pools.arcor-ip.net ([178.5.224.19] helo=[192.168.178.27]); authenticated by wp164.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) id 1Wl12m-0008BA-Fo; Thu, 15 May 2014 21:10:16 +0200 Message-ID: <53751109.5080503@marc-bennewitz.de> Date: Thu, 15 May 2014 21:10:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Chris Wright CC: PHP Internals References: <534A8121.6090205@marc-bennewitz.de> <534C2E6B.5020400@marc-bennewitz.de> <534F99A1.4070904@marc-bennewitz.de> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-bounce-key: webpack.hosteurope.de;php@marc-bennewitz.de;1400181022;8b08c17a; Subject: Re: [PHP-DEV] Shifting bits of a binary string From: php@marc-bennewitz.de (Marc Bennewitz) sorry for the late response. On 17.04.2014 11:22, Chris Wright wrote: > On 17 April 2014 10:06, Marc Bennewitz wrote: >> >> >> On 15.04.2014 02:04, Chris Wright wrote: >>> >>> On 14 April 2014 19:52, Marc Bennewitz wrote: >>>> >>>> - Bit shift left on strings: >>>> - act byte-by-byte in a O(n) manner >>>> - shifting out left bit(s) >>>> - append NULL bits to the right >>>> - preserve string length >>>> >>>> - Bit shift right on strings: >>>> - act byte-by-byte in a O(n) manner >>>> - shifting out right bit(s) >>>> - prepend NULL bits to the left (don't preserve the first bit) >>>> - preserve string length >>> >>> >>> Agreed. >>> >>>> - Bit shifting on other types: >>>> - error/warning >>> >>> >>> Probably agreed. >>> >>>> - If the number of bits to shift isn't an integer, than: >>>> - error >>> >>> >>> Floats would also need to be permitted here, albeit converted to >>> integers for the purposes of performing the operation. >> >> Ho do you handle values like 3.5? Is it an error if fractions exists? > > This would be handled as it is currently, with a standard integer > conversion, i.e. rounded towards zero. It doesn't make sense to check > for fractions and error out IMO, as floating point precision errors > would likely cause someone somewhere some unexpected behaviour. In the > case of float(3.5) it's obvious this isn't "correct", but in the case > of float(3.005) the user probably did some calculation that they > expected to result in int(3), so emitting an error would be > unexpected. While a margin of error threshold could be defined, it's > an extra branch and a somewhat arbitrary limitation. After thinking more about on operating bit operations a developer have to know about how data are represented in bits. That means the datatype to run bit operations on should never be converted automatically only an error/warning should be generated if it's not possible to run bit operations on it (like objects). That also means first bit should not be preserved as it was implemented to preserve signs of numbers. And more ... bit shifting of floating point numbers should simply be done. Because it makes little sense to do that an error could be discussable but in some special cases it could make good sense. (This would require to define data structure of floating point numbers "double" to be the same 100% on all systems) Greetings Marc