Skip to content

Commit 8811686

Browse files
committed
Math::Complex: support bare i in the imaginary part
'2+i' should parse as '2+1i'. Fixes #22711.
1 parent fd3329c commit 8811686

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

dist/Math-Complex/lib/Math/Complex.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ sub _make {
204204
($p, $q) = ($1, 0);
205205
} elsif ($arg =~ /^(?:$gre)?$gre\s*i\s*$/) {
206206
($p, $q) = ($1 || 0, $2);
207+
} elsif ($arg =~ /^(?:$gre)?\s*([+\-]?)i\s*$/) {
208+
($p, $q) = ($1 || 0, $2 . '1');
207209
} elsif ($arg =~ /^\s*\($gre\s*(?:,$gre\s*)?\)\s*$/) {
208210
($p, $q) = ($1, $2 || 0);
209211
}

dist/Math-Complex/t/Complex.t

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,22 @@ EOS
347347
print "ok $test\n";
348348
EOS
349349

350+
$test++;
351+
push @script, <<EOS;
352+
print "# remake 2+i\n";
353+
\$z = cplx('2+i');
354+
print "not " unless \$z == Math::Complex->make(2,1);
355+
print "ok $test\n";
356+
EOS
357+
358+
$test++;
359+
push @script, <<EOS;
360+
print "# make 3-i\n";
361+
\$z = Math::Complex->make('3-i');
362+
print "not " unless \$z == cplx(3,-1);
363+
print "ok $test\n";
364+
EOS
365+
350366
$test++;
351367
push @script, <<EOS;
352368
print "# emake [2,3]\n";

0 commit comments

Comments
 (0)