mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-01 21:50:18 +02:00
* patch by Rika to optimize ArcCos, resolves #40078
This commit is contained in:
parent
9998104048
commit
cfbdf90ab0
@ -1179,37 +1179,19 @@ end;
|
|||||||
{$ifdef FPC_HAS_TYPE_SINGLE}
|
{$ifdef FPC_HAS_TYPE_SINGLE}
|
||||||
function Arccos(x : Single) : Single;
|
function Arccos(x : Single) : Single;
|
||||||
begin
|
begin
|
||||||
if abs(x)=1.0 then
|
arccos:=arctan2(sqrt((1.0-x)*(1.0+x)),x);
|
||||||
if x<0.0 then
|
|
||||||
arccos:=Pi
|
|
||||||
else
|
|
||||||
arccos:=0
|
|
||||||
else
|
|
||||||
arccos:=arctan2(sqrt((1.0-x)*(1.0+x)),x);
|
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ifdef FPC_HAS_TYPE_DOUBLE}
|
{$ifdef FPC_HAS_TYPE_DOUBLE}
|
||||||
function Arccos(x : Double) : Double;
|
function Arccos(x : Double) : Double;
|
||||||
begin
|
begin
|
||||||
if abs(x)=1.0 then
|
arccos:=arctan2(sqrt((1.0-x)*(1.0+x)),x);
|
||||||
if x<0.0 then
|
|
||||||
arccos:=Pi
|
|
||||||
else
|
|
||||||
arccos:=0
|
|
||||||
else
|
|
||||||
arccos:=arctan2(sqrt((1.0-x)*(1.0+x)),x);
|
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
||||||
function Arccos(x : Extended) : Extended;
|
function Arccos(x : Extended) : Extended;
|
||||||
begin
|
begin
|
||||||
if abs(x)=1.0 then
|
arccos:=arctan2(sqrt((1.0-x)*(1.0+x)),x);
|
||||||
if x<0.0 then
|
|
||||||
arccos:=Pi
|
|
||||||
else
|
|
||||||
arccos:=0
|
|
||||||
else
|
|
||||||
arccos:=arctan2(sqrt((1.0-x)*(1.0+x)),x);
|
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
@ -37,6 +37,26 @@ begin
|
|||||||
halt(11);
|
halt(11);
|
||||||
if not(SameValue(e2,-1)) then
|
if not(SameValue(e2,-1)) then
|
||||||
halt(12);
|
halt(12);
|
||||||
|
|
||||||
|
{ ArcCos relies on ArcTan2 edge cases. }
|
||||||
|
s1:=arccos(single(1));
|
||||||
|
if s1<>0 then
|
||||||
|
halt(13);
|
||||||
|
s1:=arccos(single(-1));
|
||||||
|
if not SameValue(s1,single(pi)) then
|
||||||
|
halt(14);
|
||||||
|
d1:=arccos(double(1));
|
||||||
|
if d1<>0 then
|
||||||
|
halt(15);
|
||||||
|
d1:=arccos(double(-1));
|
||||||
|
if not SameValue(d1,double(pi)) then
|
||||||
|
halt(16);
|
||||||
|
e1:=arccos(extended(1));
|
||||||
|
if e1<>0 then
|
||||||
|
halt(17);
|
||||||
|
e1:=arccos(extended(-1));
|
||||||
|
if not SameValue(e1,extended(pi),1e-12) then
|
||||||
|
halt(18);
|
||||||
writeln('ok');
|
writeln('ok');
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user