rfc:logicalshiftoperator

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:logicalshiftoperator [2011/07/18 00:24] – Add note about <<< being used by heredoc ircmaxellrfc:logicalshiftoperator [2014/04/08 22:47] – Inactive levim
Line 1: Line 1:
 ====== Request for Comments: Add a Logical Shift Operator For Strings ====== ====== Request for Comments: Add a Logical Shift Operator For Strings ======
   * Version: 1.0   * Version: 1.0
-  * Date: 2008-03-06+  * Date: 2011-17-07
   * Author: Anthony Ferrara <ircmaxell@php.net>   * Author: Anthony Ferrara <ircmaxell@php.net>
-  * Status: Under Discussion+  * Status: Inactive
   * First Published at: http://wiki.php.net/rfc/logicalshiftoperator   * First Published at: http://wiki.php.net/rfc/logicalshiftoperator
  
Line 15: Line 15:
 The currently implemented left and right shift operators (''<<'' and ''>>'' respectively) perform [[http://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift|arithmetic shifts]].  I am proposing the introduction of a pair of [[http://en.wikipedia.org/wiki/Logical_shift|logical shift]] operators which perform their operations on arbitrary length strings. The currently implemented left and right shift operators (''<<'' and ''>>'' respectively) perform [[http://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift|arithmetic shifts]].  I am proposing the introduction of a pair of [[http://en.wikipedia.org/wiki/Logical_shift|logical shift]] operators which perform their operations on arbitrary length strings.
  
-The problem can be seen by trying to shift ''-1'' (''0xFFFFFFFF'' on 32 bit, ''0xFFFFFFFFFFFFFFFF'' on 64 bit).  If we try ''-1 >> 1'', we get back ''-1'' again.  This is due to the shift being arithmetic.  If we try ''-1 >> 2'', we will still get ''-1''.  +The problem can be seen by trying to shift ''-1'' (''0xFFFFFFFF'' on 32 bit, ''0xFFFFFFFFFFFFFFFF'' on 64 bit).  If we try ''-1 %%>>%% 1'', we get back ''-1'' again.  This is due to the shift being arithmetic.  If we try ''-1 %%>>%% 2'', we will still get ''-1''.  
  
-Additionally, the current shifts only work on strings when the string is parsable as a number.  So ''"2" >> 1'' yields ''1'' instead of the expected logical value of ''0x19''.+Additionally, the current shifts only work on strings when the string is parsable as a number.  So ''"2" %%>>%% 1'' yields ''1'' instead of the expected logical value of ''0x19''.
  
 At present, if you want to do a logical shift on a string, you need to iterate over the string and apply the shift to each part of it (where the part is less than 4 bytes long, to prevent issues on 32 bit systems).  For example: At present, if you want to do a logical shift on a string, you need to iterate over the string and apply the shift to each part of it (where the part is less than 4 bytes long, to prevent issues on 32 bit systems).  For example:
Line 37: Line 37:
 ===== Proposal ===== ===== Proposal =====
  
-I propose the addition of two new operators which will perform a logical shift.  The selection of the operators is a little bit more difficult as ''<<<'' is already taken by heredoc.  Perhaps something like ''b<<''...+I propose the addition of two new operators which will perform a logical shift.  The selection of the operators is a little bit more difficult as ''%%<<<%%'' is already taken by heredoc.  Perhaps something like ''b%%<<%%''...
  
 Example: Example:
Line 49: Line 49:
 ===== Changelog ===== ===== Changelog =====
  
- - Added note about <<< being used by heredoc already.+ - Added note about %%<<<%% being used by heredoc already.
  
rfc/logicalshiftoperator.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1