Logo

Programming-Idioms

  • PHP
  • Js

Idiom #77 Complex number

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

The complex x is moved on the 2D plane when multiplied by i
var math = require('mathjs');
var x = math.complex(-2, 3);
x = math.multiply(x, math.i);

JS has no built-in complex numbers. The math.js library was used in this example.
with Ada.Numerics.Complex_Types;
declare
   use Ada.Numerics.Complex_Types;
   X : Complex := (Re => -2.0, Im => 3.0);
begin
   X := X * i;
end;

New implementation...
< >
deleplace