Fix broken complex number conversion cases
This commit is contained in:
parent
8c65243b1a
commit
c05bbf2627
@ -174,11 +174,14 @@ namespace System {
|
||||
// Split the input into real and imaginary parts
|
||||
string[] parts = input.Split(new[] { '+', '-' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
// If starts by - (fix for -1+3i, etc)
|
||||
double factor = input.StartsWith("-") ? -1 : 1;
|
||||
|
||||
if (input.Contains("+")) {
|
||||
real = double.Parse(parts[0], CultureInfo.InvariantCulture);
|
||||
imaginary = double.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
} else if (input.LastIndexOf('-') > 0) // handling cases like "1-2i"
|
||||
{
|
||||
{
|
||||
real = double.Parse(parts[0], CultureInfo.InvariantCulture);
|
||||
imaginary = -double.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
} else if (input.StartsWith("-")) {
|
||||
@ -186,6 +189,8 @@ namespace System {
|
||||
} else {
|
||||
imaginary = double.Parse(parts[0], CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
real *= factor;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user