Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

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
#include <complex>
using namespace std::complex_literals;
	
auto x = 3i - 2.;
x *= 1i;
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;
System.Numerics;
var x = new Complex(-2, 3);
x *= Complex.ImaginaryOne;
import std.complex;
auto x = complex(-2, 3);
x * complex(0, 1);
  complex :: x
  x = (-2,3)
  x = x * (0,1)
x := 3i - 2
x *= 1i
ímport Data.Complex
x = (0 :+ 1) * ((0 - 2) :+ 3)
let i = ( 0 :+ 1 ) ; x = 3 * i - 2 in x * i
var math = require('mathjs');
var x = math.complex(-2, 3);
x = math.multiply(x, math.i);
import org.apache.commons.math4.complex.Complex;
Complex x = new Complex(-2.0, 3.0);
x = x.multiply(Complex.I);
(let ((x #c(-2 3)))
  (* x #c(0 1)))
uses ucomplex;
var
  C: Complex;
begin
  C := 3*i - 2;
end.
use Math::Complex;
my $x = cplx(-2, 3);
$x *= i;
use Math::Complex;
my $x = 3*i - 2;
$x *= i;
x = 3j-2
y = x * 1j
x = 3i - 2
x *= 1i
extern crate num;
use num::Complex;
let mut x = Complex::new(-2, 3);
x *= Complex::i();
(define x -2+3i)
(display (* x 0+1i))

New implementation...
< >
deleplace