Logo

Programming-Idioms

  • Groovy
  • Pascal
  • Scheme
  • Ada
  • VB
  • Fortran

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
  complex :: x
  x = (-2,3)
  x = x * (0,1)
uses ucomplex;
var
  C: Complex;
begin
  C := 3*i - 2;
end.
(define x -2+3i)
(display (* x 0+1i))

Most Schemes have a specialized reader syntax for complex numbers.
with Ada.Numerics.Complex_Types;
declare
   use Ada.Numerics.Complex_Types;
   X : Complex := (Re => -2.0, Im => 3.0);
begin
   X := X * i;
end;
#include <complex.h>
float complex _x = -2 + 3 * I;

_x *= I;

New implementation...
< >
deleplace