code 34611; procedure CHSH2(A1R,A1I,A2R,A2I,C,SR,SI); value A1R,A1I,A2R,A2I;real A1R,A1I,A2R,A2I,C,SR,SI; begin real R; if A2R^=0 or A2I^=0 then begin if A1R^=0 or A1I^=0 then begin R:=SQRT(A1R*A1R+A1I*A1I);C:=R; SR:=(A1R*A2R+A1I*A2I)/R;SI:=(A1R*A2I-A1I*A2R)/R; R:=SQRT(C*C+SR*SR+SI*SI);C:=C/R;SR:=SR/R;SI:=SI/R end else begin SI:=C:=0;SR:=1 end end else begin C:=1;SR:=SI:=0 end end CHSH2; eop