{"action":"created","issue":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7509","repository_url":"https://api.github.com/repos/PowerShell/PowerShell","labels_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7509/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7509/comments","events_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7509/events","html_url":"https://github.com/PowerShell/PowerShell/pull/7509","id":349881942,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA3ODY1Nzkz","number":7509,"title":"Add C#-style type accelerators and literal suffixes for short, ushort, uint, and ulong values","user":{"login":"vexx32","id":32407840,"node_id":"MDQ6VXNlcjMyNDA3ODQw","avatar_url":"https://avatars3.githubusercontent.com/u/32407840?v=4","gravatar_id":"","url":"https://api.github.com/users/vexx32","html_url":"https://github.com/vexx32","followers_url":"https://api.github.com/users/vexx32/followers","following_url":"https://api.github.com/users/vexx32/following{/other_user}","gists_url":"https://api.github.com/users/vexx32/gists{/gist_id}","starred_url":"https://api.github.com/users/vexx32/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vexx32/subscriptions","organizations_url":"https://api.github.com/users/vexx32/orgs","repos_url":"https://api.github.com/users/vexx32/repos","events_url":"https://api.github.com/users/vexx32/events{/privacy}","received_events_url":"https://api.github.com/users/vexx32/received_events","type":"User","site_admin":false},"labels":[{"id":474781609,"node_id":"MDU6TGFiZWw0NzQ3ODE2MDk=","url":"https://api.github.com/repos/PowerShell/PowerShell/labels/Breaking-Change","name":"Breaking-Change","color":"b60205","default":false},{"id":470898211,"node_id":"MDU6TGFiZWw0NzA4OTgyMTE=","url":"https://api.github.com/repos/PowerShell/PowerShell/labels/Review%20-%20Committee","name":"Review - Committee","color":"c5def5","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":30,"created_at":"2018-08-13T04:09:51Z","updated_at":"2018-08-20T10:04:14Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/PowerShell/PowerShell/pulls/7509","html_url":"https://github.com/PowerShell/PowerShell/pull/7509","diff_url":"https://github.com/PowerShell/PowerShell/pull/7509.diff","patch_url":"https://github.com/PowerShell/PowerShell/pull/7509.patch"},"body":"## PR Summary\r\n\r\nImplements 'u' and 's' token case in the Tokenizer.cs and CharTraits.cs parsing which allows the use of uint or short literals as numbers with a 'u' and/or 's' suffix:\r\n```powershell\r\nPS> $Value = 108u\r\nPS> $Value.GetType().FullName\r\nSystem.UInt32\r\n\r\nPS> $Short = 105.5us\r\nPS> $Short\r\n106\r\nPS> $Short.GetType().FullName\r\nSystem.UInt16\r\n```\r\n\r\nI also tidied up some of the code in the vicinity to inline some of the very temporary variable definitions.\r\n\r\nComprehensive Summary:\r\n\r\n* Adds type suffixes for `u` and `s` - `uint` and `short`, respectively.\r\n* Adds some logic to test whether `UInt32` or `UInt64` is the appropriate return type by comparing the multiplied value against `UIUnt32.MaxValue` when neither `l` nor `s` is supplied.\r\n* Adds `[short]`, `[ushort]`, `[uint]`, and `[ulong]` type accelerators to help out people coming from C# or other languages. Mapped to `int16`, `uint16`, `uint32`, and `uint64`, respectively.\r\n* Maintains parity with existing `l` / `L` suffix, where it will also perform rounding functions when applied to a `real` literal while also ensuring it still returns an appropriate `uint` or `ulong` value: `105.5u => 106`\r\n* Defines a new flags enum `NumberSuffixFlags` that takes care of one-or-more numerical type suffixes.\r\n* Can explicitly parse `ul`-suffixed numeric values as `ulong` and `us`-suffixed values as `ushort`.\r\n* Explicitly specified length types for `short` and `long` as well as declared `unsigned` types **will** error out and register as an invalid numeric literal if their values after multiplication exceeds the type contraints. This is intentional; if the user specifies a value that cannot be satisfied e.g., `500sgb` (500 short, gigabyte multiplier) then the parser should not be expected to figure out what they meant. \r\n* Converts `strNum` parameter of `TryGetNumberValue` to `ReadOnlySpan<char>` to hopefully get a little better performance as it flies through all the `TryParse`s.\r\n\r\n## PR Checklist\r\n\r\n- [X] [PR has a meaningful title](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)\r\n    - Use the present tense and imperative mood when describing your changes\r\n- [X] [Summarized changes](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)\r\n- [X] [Make sure all `.h`, `.cpp`, `.cs`, `.ps1` and `.psm1` files have the correct copyright header](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)\r\n- [X] This PR is ready to merge and is not [Work in Progress](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---work-in-progress).\r\n    - If the PR is work in progress, please add the prefix `WIP:` to the beginning of the title and remove the prefix when the PR is ready.\r\n- **User-facing changes**\r\n    - [X] User-facing [Documentation needed](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request---submission)\r\n        - [ ] Issue filed - Issue link:\r\n- **Testing - New and feature**\r\n    - [x] [Make sure you've added a new test if existing tests do not effectively test the code changed](https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#before-submitting)\r\n        - [ ] [Add `[feature]` if the change is significant or affects feature tests](https://github.com/PowerShell/PowerShell/blob/master/docs/testing-guidelines/testing-guidelines.md#requesting-additional-tests-for-a-pr)\r\n\r\n(not sure on *all* of those points; never worked on this repo before; feel free to let me know about stuff I'm missing)"},"comment":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/comments/414264623","html_url":"https://github.com/PowerShell/PowerShell/pull/7509#issuecomment-414264623","issue_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7509","id":414264623,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNDI2NDYyMw==","user":{"login":"iSazonov","id":22290914,"node_id":"MDQ6VXNlcjIyMjkwOTE0","avatar_url":"https://avatars2.githubusercontent.com/u/22290914?v=4","gravatar_id":"","url":"https://api.github.com/users/iSazonov","html_url":"https://github.com/iSazonov","followers_url":"https://api.github.com/users/iSazonov/followers","following_url":"https://api.github.com/users/iSazonov/following{/other_user}","gists_url":"https://api.github.com/users/iSazonov/gists{/gist_id}","starred_url":"https://api.github.com/users/iSazonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iSazonov/subscriptions","organizations_url":"https://api.github.com/users/iSazonov/orgs","repos_url":"https://api.github.com/users/iSazonov/repos","events_url":"https://api.github.com/users/iSazonov/events{/privacy}","received_events_url":"https://api.github.com/users/iSazonov/received_events","type":"User","site_admin":false},"created_at":"2018-08-20T10:04:14Z","updated_at":"2018-08-20T10:04:14Z","author_association":"COLLABORATOR","body":"As for sign:\r\n1. Currently PowerShell implement \r\n```powershell\r\n-0x1A\r\n\r\n-26\r\n```\r\n2. Currently PowerShell CAN consider hex numerics as signed\r\n```powershell\r\n>0xFFFFFFFF\r\n\r\n-1\r\n\r\n>(0xFFFFFFFF).Gettype()\r\n\r\nIsPublic IsSerial Name                                     BaseType\r\n-------- -------- ----                                     --------\r\nTrue     True     Int32                                    System.ValueType\r\n```\r\n3. Current PowerShell behavior is to consider high bit as sign _because target type always is signed_ - int32/64/long/double/BigInteger.\r\n\r\n4. If target type is unsigned (ushort,uint,ulong and so on) PowerShell MUST to consider high bit as value not sign\r\nThe behavior is in CoreFX https://source.dot.net/#System.Private.CoreLib/shared/System/Number.Parsing.cs,890\r\n```\r\n5. Because we want add binary literals we should consider them here too. PowerShell must process binary literals in the same manner as hex literals.\r\n"}}
{"actor":{"display_login":"iSazonov"}}