-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Description
To better support formatting values with culture-specific information, the default string representation of complex numbers was changed to avoid using characters that can be used in formatted numeric values. This change affects Complex.ToString, where the value is now formatted as <a; b> instead of (a, b).
This breaking change did not get an issue created at the time of .NET 8 GA, but was reported in dotnet/runtime#93454.
Version
.NET 8 GA
Previous behavior
The string representation of the complex number returned by Complex.ToString displays the number using its Cartesian coordinates in the form (a, b), where a is the real part of the complex number, and b is its imaginary part. Both a and b are formatted using the general format specifier ("G") and the conventions of the culture defined by provider.
New behavior
The string representation of the complex number returned by Complex.ToString displays the number using its Cartesian coordinates in the form <a; b>, where a is the real part of the complex number, and b is its imaginary part. Both a and b are formatted using the general format specifier ("G") and the conventions of the culture defined by provider.
Type of breaking change
- Binary incompatible: Existing binaries might encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
- Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code might require source changes to compile successfully.
- Behavioral change: Existing binaries might behave differently at run time.
Reason for change
The change to use semicolon allows support of formatting with culture specific information and correspondingly need to be able to parse results back out given it implements INumberBase<T>.
The change from parentheses (( )) to angle brackets avoids potential collision with numeric formats where negative numbers are formatted as (x), and this is also consistent with the Vector* types' behavior.
Recommended action
If the previous format is needed, a custom string formatting mechanism such as $"({complex.Real}, {complex.Imaginary})" can be used to produce the string in the old format.
Feature area
Core .NET libraries