Functions "carg_ch" and "carg_th" of unit "ucomplex" yield wrong results.
Original Reporter info from Mantis: Antonio Puente
-
Reporter name: Antonio Puente Rodero
Original Reporter info from Mantis: Antonio Puente
- Reporter name: Antonio Puente Rodero
Description:
Function "carg_ch" is currently coded as follows:
function carg_ch (z : complex) : complex;
{ hyberbolic arg cosinus }
{ _________ }
{ argch(z) = -/+ ln(z + i.V 1 - z.z) }
begin
carg_ch:=-cln(z+i*csqrt(z*z-1.0));
end;
To work well, it should ve coded as:
function carg_ch (z : complex) : complex;
{ hyberbolic arg cosinus }
{ _________ }
{ argch(z) = -/+ ln(z + i.V 1 - z.z) }
begin
carg_ch:=cln(z+i*csqrt(1.0-z*z));
end;
Similarly, function "carg_th" should replace:
function carg_th (z : complex) : complex;
{ hyperbolic arc tangent }
{ argth(z) = 1/2 ln((z + 1) / (1 - z)) }
begin
carg_th:=cln((z+1.0)/(z-1.0))/2.0; // <- wrong code
end;
by
function carg_th (z : complex) : complex;
{ hyperbolic arc tangent }
{ argth(z) = 1/2 ln((z + 1) / (1 - z)) }
begin
carg_th:=cln((z+1.0)/(1.0-z))/2.0; // <- correct code
end;
Amazingly, the formulas given in the comments of both functions are correct.
Steps to reproduce:
Drop an edit box, a button and two labels on a form. Add the following code to the on-click event of the button:
procedure TForm1.Button1Click(Sender: TObject);
var
Angle, Y: Complex;
begin
{ Reads a real number from Edit1 and puts it on "Angle" }
Angle.Re := StrToFloat(Edit1.Text);
Angle.Im := 0;
{ Calculates the hyperbolic cosinus of "Angle" on "Y"
and shows the result in Label1 }
Y := cch(Angle);
Label1.Caption := 'Value of cch(Angle1): '+cstr(Y);
{ Calculates the inverse hyperbolic cosinus of "Y"
and shows the result in Label2 }
Label2.Caption := 'Value of arg_ch(cch(Angle)): '+cstr(carg_ch(Y));
end;
This code may be tested with several real values and the results compared with those calculated by a pocked calculator. If the function "carg_ch" worked well, the value got in Label2.Caption should be the same of the one contained in Edit1.Text.
A similar test may be done for "carg_th".
Additional information:
Functions "carc_cos" and "carc_tg" are also impacted by these bugs because they use "carg_ch" and "carg_th" respectively.
Mantis conversion info:
- Mantis ID: 18844
- OS: All
- OS Build: All
- Platform: All
- Version: 2.4.2
- Fixed in version: 2.6.0
- Fixed in revision: 17253 (#f2a3f4e5)