-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
[bigint] '1,000'Note:
-
The root cause is the specification of incompatible
NumberStyleflags here: It usesNumberStyles.AllowDecimalPointandNumberStyles.AllowExponentandNumberStyles.AllowLeadingSign, none of which may be combined withNumberStyles.AllowHexSpecifier -
In its current form, the linked call is pointless altogether: While the ostensible fix is to use only
NumberStyles.AllowHexSpecifier, this would parse something like'10'as16(e.g.,[bigint]::parse('10', 'allowhexspecifier')) -
Omitting the call would mean that values with
,are handled via the fallback toConvertNumericThroughDouble(), as for the primitive integer types, but note that this can result in a loss of precision:-
As an aside: This loss of precision already occurs due to the initial parsing via
TryScanNumber()treating larger-than-[decimal]numbers as[double]; e.g.,[bigint] '99999999999999999999999999999'yields99999999999999991433150857216(!); see also: -
Similarly, the
ConvertNumericThroughDouble()fallback is problematic for[long]and[ulong]casts with integer string values that contain,(which the initialTryScanNumber()call doesn't recognize), e.g.,[long] '9223372036854775,807'fails, because the[double]detour results in a value too large for a[long](the input value is, in effect,[long]::MaxValue), and something like[long] '9223372036854775,000'results in a loss of precision (yields9223372036854774784)
-
Expected behavior
1000Actual behavior
An exception occurs:
InvalidArgument: Cannot convert value "1,000" to type "System.Numerics.BigInteger".
Error: "With the AllowHexSpecifier bit set in the enum bit field, the only other valid bits
that can be combined into the enum value must be a subset of those in HexNumber. (Parameter 'style')"Error details
Environment data
PowerShell 7.5.0, 7.6.0-preview.3Visuals
No response