[Breaking change]: Complex.ToString format changed from (a, b)
to <a; b>
#41835
Labels
breaking-change
Indicates a .NET Core breaking change
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
in-pr
This issue will be closed (fixed) by an active pull request.
Pri1
High priority, do before Pri2 and Pri3
📌 seQUESTered
Identifies that an issue has been imported into Quest.
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)
, wherea
is the real part of the complex number, andb
is its imaginary part. Botha
andb
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>
, wherea
is the real part of the complex number, andb
is its imaginary part. Botha
andb
are formatted using the general format specifier ("G") and the conventions of the culture defined by provider.Type of breaking change
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 theVector*
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
Affected APIs
Associated WorkItem - 292108
The text was updated successfully, but these errors were encountered: