PageSourceSearch

https://refractiveindex.info/include/complex.js?ver=2025-01-11

js refractiveindex.info collected 2026-10-01 11:32:26 UTC 1,906 bytes, 81 lines download raw bytes

1function Complex(re,im){
2this.re=re;
3this.im=im;
4};
5//a+b
6Complex.add=function(a,b){
7return new Complex(a.re+b.re,a.im+b.im);
8};
9//a-b
10Complex.sub=function(a,b){
11return new Complex(a.re-b.re,a.im-b.im);
12};
13//a*b
14Complex.mult=function(a,b){
15return new Complex(a.re*b.re-a.im*b.im,a.re*b.im+a.im*b.re);
16};
17//Cartesian to polar
18Complex.car2pol=function(c){
19return new Complex(Complex.abs(c),Math.atan2(c.im,c.re));
20};
21//polar to Cartesian
22Complex.pol2car=function(c){
23return new Complex(c.re*Math.cos(c.im),c.re*Math.sin(c.im));
24};
25//a/b
26Complex.div=function(a,b){
27a=Complex.car2pol(a);
28b=Complex.car2pol(b);
29var c=new Complex(a.re/b.re, a.im-b.im);
30return Complex.pol2car(c);
31};
32//sin(x+iy)=sin(x)*cosh(y)+i*cos(x)*sinh(y)
33Complex.sin=function(c){
34return new Complex(Math.sin(c.re)*Math.cosh(c.im),Math.cos(c.re)*Math.sinh(c.im));
35};
36//cos(x+iy)=cos(x)*cosh(y)-i*sin(x)*sinh(y)
37Complex.cos=function(c){
38return new Complex(Math.cos(c.re)*Math.cosh(c.im),-1.0*Math.sin(c.re)*Math.sinh(c.im));
39};
40//conjugate
41Complex.conj=function(c){
42return new Complex(c.re,-1.0*c.im);
43};
44//abs
45Complex.abs=function(c){
46return Math.sqrt(c.re*c.re+c.im*c.im);
47};
48//abs^2
49Complex.abs2=function(c){
50return c.re*c.re+c.im*c.im;
51};
52//sqrt
53Complex.sqrt=function(c){
54c=Complex.car2pol(c);	
55c.re=Math.sqrt(c.re);
56c.im=c.im/2.0;
57return Complex.pol2car(c);
58};
59//a^b
60Complex.pow=function(a,b){
61var c=Complex.car2pol(a);
62c.re=Math.pow(c.re,b);
63c.im=c.im*b;
64return Complex.pol2car(c);
65};
66//exp: e^(x + i y) = e^x * [cos(y) + i sin(y)]
67Complex.exp = function(c){
68return new Complex(Math.exp(c.re) * Math.cos(c.im), Math.exp(c.re) * Math.sin(c.im));
69};
70//negative
71Complex.prototype.neg=function(){
72return new Complex(-c.re,-c.im);
73};
74//to string
75Complex.prototype.toString=function(){
76return "{" + c.re + "," + c.im + "}";
77};
78// misc complex constants
79Complex.zero=new Complex(0,0);
80Complex.one=new Complex(1,0);
81Complex.i=new Complex(0,1);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.