Logo

Programming-Idioms

History of Idiom 77 > diff from v14 to v15

Edit summary for version 15 by :
New JS implementation by user [Patman64]

Version 14

2016-01-21, 09:18:19

Version 15

2016-02-16, 20:21:03

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
var math = require('mathjs');
Code
var x = math.complex(-2, 3);
x = math.multiply(x, math.i);
Comments bubble
JS has no built-in complex numbers. The math.js library was used in this example.
Doc URL
http://mathjs.org/docs/datatypes/complex_numbers.html