Logo

Programming-Idioms

History of Idiom 77 > diff from v4 to v5

Edit summary for version 5 by :

Version 4

2015-08-24, 21:46:43

Version 5

2015-08-31, 11:55:44

Idiom #77 Complex number

Declare a complex x and initialize it with value (3i - 2). Then multiply it by i.

Idiom #77 Complex number

Declare a complex x and initialize it with value (3i - 2). Then multiply it by i.

Imports
use Math::Complex;
Code
# Simple version: Clear, but less efficient
my $x = 3*i - 2;
$x *= i;

# Efficient version: faster
my $x = cplx(-2, 3);
$x *= i;
Comments bubble
The simple starts with i, then uses a multiplication and a subtraction to build the complex number. The efficient version does it in one step.