Skip to content
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

Convert.ChangeType(infinity, float/double) throws an error on Linux in .NET 6/7/8 #100197

Closed
Bartleby2718 opened this issue Mar 24, 2024 · 2 comments

Comments

@Bartleby2718
Copy link

Description

System.Convert.ChangeType(...) cannot convert positive or negative infinity to float or double in .NET 6/7/8.

Reproduction Steps

Expected behavior

On all supported OSes and on all versions of .NET:

Actual behavior

They all throw on Linux.

Regression?

This has never worked in the past few major versions of .NET (Core). Didn't test EOL'd version of .NET (Core).

Known Workarounds

Special-case "∞" and "-∞"

Configuration

  • .NET version: 6, 7, 8
  • OS version: Ubuntu 22.04

Other information

No response

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Mar 24, 2024
@huoyaoyuan
Copy link
Member

Convert.ChangeType calls float.Parse and double.Parse. They only match PositiveInfinitySymbol and NegativeInfinitySymbol of current culture, which differ from OS and versions. You can print CultureInfo.CurrentCulture.NumberFormat.PositiveInfinitySymbol to verify. It prints Infinity for me on Linux.

@Bartleby2718
Copy link
Author

@huoyaoyuan That was it! Good to know how this works under the hood.

Closing.

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Mar 24, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Apr 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants