-
Notifications
You must be signed in to change notification settings - Fork 8.2k
PowerShell doesn't understand unsigned numbers #3313
Copy link
Copy link
Closed
Labels
Committee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.The issue is fixed.WG-Languageparser, language semanticsparser, language semantics
Metadata
Metadata
Assignees
Labels
Committee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.The issue is fixed.WG-Languageparser, language semanticsparser, language semantics
Steps to reproduce
Description: I can't make powershell use correctly types like [uint32] or [uint64]. It seems like it always tries to dumb down every number to [int], and does it poorly. The bug seems to be that PS doesn't realize that is has to upcast 0xffffffff to int64 and not to int32, as it won't fit.
PS C:> [uint32]$b=0xffffffff
Cannot convert value "-1" to type "System.UInt32". Error: "Value was either too large or too small for a UInt32."
PS C:> $b=[uint32]0xffffffff
Cannot convert value "-1" to type "System.UInt32". Error: "Value was either too large or too small for a UInt32."
PS C:> $b=[uint64]0x1ffffffff
<so this works, because powershell realizes that 1ffffffff doesn't fit into 31 bit>
PS C:> $b=[uint64]0xffffffff
Cannot convert value "-1" to type "System.UInt64". Error: "Value was either too large or too small for a UInt64."
Expected behavior
PS C:\ > [uint32]$b = 0xffffffff
PS C:\ > $b
4294967295
Actual behavior
PS C:> [uint32]$b = 0xffffffff
Cannot convert value "-1" to type "System.UInt32". Error: "Value was either too large or too small for a UInt32."
At line:1 char:1
Environment data