-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Use correct NumberStyle when parsing double and float #59205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use correct NumberStyle when parsing double and float #59205
Conversation
IParseable<float> and IParseable<double> would fail when parsing a decimal point number due to incorrect NumberStyles parameter. E.g. IParseable<double>.TryParse would fail as opposed to IParseable<double>.Parse because the former explicitly states to use NumberStyles.Integer
|
Tagging subscribers to this area: @dotnet/area-system-numerics Issue Details
E.g.
|
tannergooding
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
CC. @jeffhandley, can we do a bar check for this? |
|
+1 on backporting this, especially considering that it's behind a preview attribute |
|
This has my support for either RC2 or GA. Customer-reported and fixed functional issue in new functionality introduced in a late preview, plus the changes are limited to the Generic Math Preview feature. @danmoseley, what do you think? |
|
I'll merge this PR either way after and then backport and fill in the template if Dan also thinks its fine to take. |
|
I think we can take changes to the preview paths for a while, including this one. Assuming risk to existing codepaths is negligible. So yeah please template and PR against RC2 if you want to. |
| { | ||
| if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); | ||
| return Number.ParseHalf(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.GetInstance(provider)); | ||
| return Number.ParseHalf(s, DefaultParseStyle, NumberFormatInfo.GetInstance(provider)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting that this and above are the only changes to non preview code and they're a no-op. (It might have been nice if we used DefaultParseStyle in Float and Double or not at all, so they look the same)
|
Can we include tests please? |
|
@danmoseley, I'll add some basic tests. I don't think we want to duplicate all the parsing tests as these explicit bindings are going away here shortly (they were only for .NET 6 to help separate stable vs experimental APIs). |
MSBuild_Logs/MSBuild_pid-37116_6904092b1c9a481da960c9e28eba2a27.failure.txt
Outdated
Show resolved
Hide resolved
|
/backport to release/6.0 |
|
Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1254170359 |
|
/backport to release/6.0-rc2 |
|
Started backporting to release/6.0-rc2: https://github.com/dotnet/runtime/actions/runs/1254861149 |
IParseable<float>andIParseable<double>would fail when parsing a decimal point number due to incorrectNumberStylesparameter.E.g.
IParseable<double>.TryParsewould fail as opposed toIParseable<double>.Parsebecause the former explicitly states to useNumberStyles.Integer