Logo

Programming-Idioms

History of Idiom 77 > diff from v8 to v9

Edit summary for version 9 by :

Version 8

2015-09-30, 11:47:07

Version 9

2015-09-30, 11:48:25

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;
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;
Code
my $x = 3*i - 2;
$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.
Comments bubble
Simple version: clear, but not efficient. It starts with i, then uses a multiplication and a subtraction to build the complex number.