Kind Value Label
---- ----- -----
Double 6.21 i int, i d
Decimal 6.21 i int, ex d
Int32 6 i int, ex int
Decimal 6.21 ex int, ex d
Double 6.21 ex int, i double
Int32 65535 int32
BigInteger 65535 BigInt
Int16 -1 if 7.1, this becomes -1 [int16] / short
Last active
November 2, 2024 21:16
-
-
Save ninmonkey/96d095c87f14a14179dc0aafb5babf73 to your computer and use it in GitHub Desktop.
Test which conversions occur in pwsh numeric literals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @' | |
| There's a bunch of literals added in 6+ | |
| 7.1 added | |
| > using a type suffix on a hex literal now returns a signed value of that type | |
| https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_numeric_literals?view=powershell-7.5 | |
| '@ | |
| 100 - 93.79 | ty 'i int, i d' | |
| 100 - 93.79d | ty 'i int, ex d' | |
| 100 - ([int]93.79) | ty 'i int, ex int' | |
| ([int]100) - (93.79d) | ty 'ex int, ex d' | |
| ([int]100) - (93.79) | ty 'ex int, i double' | |
| 0xffff | Ty 'int32' | |
| 0xffffn| Ty 'BigInt' | |
| 0xffffs | Ty 'if 7.1, this becomes -1 [int16] / short' | |
| Function Ty { | |
| # summarize output | |
| param( [string] $Label ) | |
| process { | |
| [pscustomobject]@{ | |
| Kind = ($_)?.GetType().Name ?? 'null' | |
| Value = $_ ; | |
| Label = $Label | |
| } } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment