mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-12-16 00:50:40 +01:00
* ensure that the final assignment in the hyperbolic functions raises an exception if they overflow
This commit is contained in:
parent
266662971b
commit
1850eab89a
@ -1263,24 +1263,35 @@ function arctan2(y,x : float) : float;
|
||||
end;
|
||||
{$endif FPC_MATH_HAS_ARCTAN2}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_SINGLE}
|
||||
function cosh(x : Single) : Single;
|
||||
var
|
||||
temp : ValReal;
|
||||
begin
|
||||
temp:=exp(x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
cosh:=0.5*(temp+1.0/temp);
|
||||
{$pop}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_DOUBLE}
|
||||
function cosh(x : Double) : Double;
|
||||
var
|
||||
temp : ValReal;
|
||||
begin
|
||||
temp:=exp(x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
cosh:=0.5*(temp+1.0/temp);
|
||||
{$pop}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
||||
function cosh(x : Extended) : Extended;
|
||||
var
|
||||
@ -1300,9 +1311,14 @@ function sinh(x : Single) : Single;
|
||||
{ gives better behavior around zero, and in particular ensures that sinh(-0.0)=-0.0 }
|
||||
if temp=1 then
|
||||
exit(x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
sinh:=0.5*(temp-1.0/temp);
|
||||
{$pop}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_DOUBLE}
|
||||
function sinh(x : Double) : Double;
|
||||
var
|
||||
@ -1311,9 +1327,14 @@ function sinh(x : Double) : Double;
|
||||
temp:=exp(x);
|
||||
if temp=1 then
|
||||
exit(x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
sinh:=0.5*(temp-1.0/temp);
|
||||
{$pop}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
||||
function sinh(x : Extended) : Extended;
|
||||
var
|
||||
@ -1326,6 +1347,7 @@ function sinh(x : Extended) : Extended;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_SINGLE}
|
||||
function tanh(x : Single) : Single;
|
||||
var
|
||||
@ -1335,16 +1357,24 @@ function tanh(x : Single) : Single;
|
||||
tmp:=exp(2*x);
|
||||
if tmp=1 then
|
||||
exit(x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
result:=(tmp-1)/(1+tmp)
|
||||
{$pop}
|
||||
end
|
||||
else begin
|
||||
tmp:=exp(-2*x);
|
||||
if tmp=1 then
|
||||
exit(x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
result:=(1-tmp)/(1+tmp)
|
||||
{$pop}
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_DOUBLE}
|
||||
function tanh(x : Double) : Double;
|
||||
var
|
||||
@ -1354,16 +1384,24 @@ function tanh(x : Double) : Double;
|
||||
tmp:=exp(2*x);
|
||||
if tmp=1 then
|
||||
exit(x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
result:=(tmp-1)/(1+tmp)
|
||||
{$pop}
|
||||
end
|
||||
else begin
|
||||
tmp:=exp(-2*x);
|
||||
if tmp=1 then
|
||||
exit(x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
result:=(1-tmp)/(1+tmp)
|
||||
{$pop}
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
||||
function tanh(x : Extended) : Extended;
|
||||
var
|
||||
@ -1393,18 +1431,28 @@ begin
|
||||
//https://en.wikipedia.org/wiki/Hyperbolic_functions#Definitions
|
||||
//SecH = 2 / (e^X + e^-X)
|
||||
Ex:=Exp(X);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
SecH:=2/(Ex+1/Ex);
|
||||
{$pop}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_DOUBLE}
|
||||
function SecH(const X: Double): Double;
|
||||
var
|
||||
Ex: ValReal;
|
||||
begin
|
||||
Ex:=Exp(X);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
SecH:=2/(Ex+1/Ex);
|
||||
{$pop}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
||||
function SecH(const X: Extended): Extended;
|
||||
var
|
||||
@ -1422,18 +1470,28 @@ var
|
||||
begin
|
||||
//CscH = 2 / (e^X - e^-X)
|
||||
Ex:=Exp(X);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
CscH:=2/(Ex-1/Ex);
|
||||
{$pop}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_DOUBLE}
|
||||
function CscH(const X: Double): Double;
|
||||
var
|
||||
Ex: ValReal;
|
||||
begin
|
||||
Ex:=Exp(X);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
CscH:=2/(Ex-1/Ex);
|
||||
{$pop}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
||||
function CscH(const X: Extended): Extended;
|
||||
var
|
||||
@ -1453,16 +1511,24 @@ begin
|
||||
e2:=exp(2*x);
|
||||
if e2=1 then
|
||||
exit(1/x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
result:=(1+e2)/(e2-1)
|
||||
{$pop}
|
||||
end
|
||||
else begin
|
||||
e2:=exp(-2*x);
|
||||
if e2=1 then
|
||||
exit(1/x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
result:=(1+e2)/(1-e2)
|
||||
{$pop}
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_DOUBLE}
|
||||
function CotH(const X: Double): Double;
|
||||
var
|
||||
@ -1472,16 +1538,24 @@ begin
|
||||
e2:=exp(2*x);
|
||||
if e2=1 then
|
||||
exit(1/x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
result:=(1+e2)/(e2-1)
|
||||
{$pop}
|
||||
end
|
||||
else begin
|
||||
e2:=exp(-2*x);
|
||||
if e2=1 then
|
||||
exit(1/x);
|
||||
{$push}
|
||||
{$safefpuexceptions on}
|
||||
result:=(1+e2)/(1-e2)
|
||||
{$pop}
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$ifdef FPC_HAS_TYPE_EXTENDED}
|
||||
function CotH(const X: Extended): Extended;
|
||||
var
|
||||
|
||||
Loading…
Reference in New Issue
Block a user