[prev] [prev-tail] [tail] [up]

### 13.3 Functions and Procedures

#### arccos

Declaration:
  Function arccos(x : float) : float;
Description:
  Arccos returns the inverse cosine of its argument x. The argument x should lie between -1 and 1 (borders included).
Errors:
  If the argument x is not in the allowed range, an EInvalidArgument exception is raised.
See also:
  arcsin (457), arcosh (456), arsinh (459), artanh (459)

Listing: mathex/ex1.pp

Program Example1;
{ Program to demonstrate the arccos function. }
Uses math;
Procedure WriteRadDeg(X : float);
begin
Writeln(X:8:5,' rad = ',radtodeg(x):8:5,' degrees.')
end;
begin
WriteRadDeg (arccos(1));
WriteRadDeg (arccos(sqrt(3)/2));
WriteRadDeg (arccos(sqrt(2)/2));
WriteRadDeg (arccos(1/2));
WriteRadDeg (arccos(0));
WriteRadDeg (arccos(-1));
end.

#### arcosh

Declaration:
  Function arcosh(x : float) : float; Function arccosh(x : float) : float;
Description:
  Arcosh returns the inverse hyperbolic cosine of its argument x. The argument x should be larger than 1.

  The arccosh variant of this function is supplied for Delphicompatibility.

Errors:
  If the argument x is not in the allowed range, an EInvalidArgument exception is raised.
See also:
  cosh (460), sinh (485), arcsin (457), arsinh (459), artanh (459), tanh (489)

Listing: mathex/ex3.pp

Program Example3;
{ Program to demonstrate the arcosh function. }
Uses math;
begin
Writeln(arcosh(1));
Writeln(arcosh(2));
end.

#### arcsin

Declaration:
  Function arcsin(x : float) : float;
Description:
  Arcsin returns the inverse sine of its argument x. The argument x should lie between -1 and 1.
Errors:
  If the argument x is not in the allowed range, an EInvalidArgument exception is raised.
See also:
  arccos (456), arcosh (456), arsinh (459), artanh (459)

Listing: mathex/ex2.pp

Program Example1;
{ Program to demonstrate the arcsin function. }
Uses math;
Procedure WriteRadDeg(X : float);
begin
Writeln(X:8:5,' rad = ',radtodeg(x):8:5,' degrees.')
end;
begin
WriteRadDeg (arcsin(1));
WriteRadDeg (arcsin(sqrt(3)/2));
WriteRadDeg (arcsin(sqrt(2)/2));
WriteRadDeg (arcsin(1/2));
WriteRadDeg (arcsin(0));
WriteRadDeg (arcsin(-1));
end.

#### arctan2

Declaration:
  Function arctan2(x,y : float) : float;
Description:
  arctan2 calculates arctan(y/x), and returns an angle in the correct quadrant. The returned angle will be in the range - to radians. The values of x and y must be between -2^64 and 2^64, moreover x should be different from zero.

  On Intel systems this function is implemented with the native intel fpatan instruction.

Errors:
  If x is zero, an overflow error will occur.
See also:
  arccos (456), arcosh (456), arsinh (459), artanh (459)

Listing: mathex/ex6.pp

Program Example6;
{ Program to demonstrate the arctan2 function. }
Uses math;
Procedure WriteRadDeg(X : float);
begin
Writeln(X:8:5,' rad = ',radtodeg(x):8:5,' degrees.')
end;
begin
WriteRadDeg (arctan2(1,1));
end.

#### arsinh

Declaration:
  Function arsinh(x : float) : float; Function arcsinh(x : float) : float;
Description:
  arsinh returns the inverse hyperbolic sine of its argument x.

  The arscsinh variant of this function is supplied for Delphicompatibility.

Errors:
  None.
See also:
  arcosh (456), arccos (456), arcsin (457), artanh (459)

Listing: mathex/ex4.pp

Program Example4;
{ Program to demonstrate the arsinh function. }
Uses math;
begin
Writeln(arsinh(0));
Writeln(arsinh(1));
end.

#### artanh

Declaration:
  Function artanh(x : float) : float; Function arctanh(x : float) : float;
Description:
  artanh returns the inverse hyperbolic tangent of its argument x, where x should lie in the interval [-1,1], borders included.

  The arctanh variant of this function is supplied for Delphicompatibility.

Errors:
  In case x is not in the interval [-1,1], an EInvalidArgument exception is raised.
See also:
  arcosh (456), arccos (456), arcsin (457), artanh (459)
Errors:
See also:

Listing: mathex/ex5.pp

Program Example5;
{ Program to demonstrate the artanh function. }
Uses math;
begin
Writeln(artanh(0));
Writeln(artanh(0.5));
end.

#### ceil

Declaration:
  Function ceil(x : float) : longint;
Description:
  Ceil returns the lowest integer number greater than or equal to x. The absolute value of x should be less than maxint.
Errors:
  If the asolute value of x is larger than maxint, an overflow error will occur.
See also:
  floor (463)

Listing: mathex/ex7.pp

Program Example7;
{ Program to demonstrate the Ceil function. }
Uses math;
begin
Writeln(Ceil(-3.7)); // should be -3
Writeln(Ceil(3.7)); // should be 4
Writeln(Ceil(-4.0)); // should be -4
end.

#### cosh

Declaration:
  Function cosh(x : float) : float;
Description:
  Cosh returns the hyperbolic cosine of it’s argument x.
Errors:
  None.
See also:
  arcosh (456), sinh (485), arsinh (459)

Listing: mathex/ex8.pp

Program Example8;
{ Program to demonstrate the cosh function. }
Uses math;
begin
Writeln(Cosh(0));
Writeln(Cosh(1));
end.

#### cotan

Declaration:
  Function cotan(x : float) : float;
Description:
  Cotan returns the cotangent of it’s argument x. x should be different from zero.
Errors:
  If x is zero then a overflow error will occur.
See also:
  tanh (489)

Listing: mathex/ex9.pp

Program Example9;
{ Program to demonstrate the cotan function. }
Uses math;
begin
writeln(cotan(pi/2));
Writeln(cotan(pi/3));
Writeln(cotan(pi/4));
end.

#### cycletorad

Declaration:
  Function cycletorad(cycle : float) : float;
Description:
  Cycletorad transforms it’s argument cycle (an angle expressed in cycles) to radians. (1 cycle is 2 radians).
Errors:
  None.
See also:
  degtograd (462), degtorad (463), radtodeg (482), radtograd (482), radtocycle (481)

Listing: mathex/ex10.pp

Program Example10;
{ Program to demonstrate the cycletorad function. }
Uses math;
begin
writeln(cos(cycletorad(1/6))); // Should print 1/2
writeln(cos(cycletorad(1/8))); // should be sqrt(2)/2
end.

#### degtograd

Declaration:
  Function degtograd(deg : float) : float;
Description:
  Degtograd transforms it’s argument deg (an angle in degrees) to grads.

  (90 degrees is 100 grad.)

Errors:
  None.
See also:
  cycletorad (461), degtorad (463), radtodeg (482), radtograd (482), radtocycle (481)

Listing: mathex/ex11.pp

Program Example11;
{ Program to demonstrate the degtograd function. }
Uses math;
begin
writeln(degtograd(90));
writeln(degtograd(180));
writeln(degtograd(270))
end.

#### degtorad

Declaration:
  Function degtorad(deg : float) : float;
Description:
  Degtorad converts it’s argument deg (an angle in degrees) to radians.

  (pi radians is 180 degrees)

Errors:
  None.
See also:
  cycletorad (461), degtograd (462), radtodeg (482), radtograd (482), radtocycle (481)

Listing: mathex/ex12.pp

Program Example12;
{ Program to demonstrate the degtorad function. }
Uses math;
begin
writeln(degtorad(45));
writeln(degtorad(90));
writeln(degtorad(180));
writeln(degtorad(270));
writeln(degtorad(360));
end.

#### floor

Declaration:
  Function floor(x : float) : longint;
Description:
  Floor returns the largest integer smaller than or equal to x. The absolute value of x should be less than maxint.
Errors:
  If x is larger than maxint, an overflow will occur.
See also:
  ceil (460)

Listing: mathex/ex13.pp

Program Example13;
{ Program to demonstrate the floor function. }
Uses math;
begin
Writeln(Ceil(-3.7)); // should be -4
Writeln(Ceil(3.7)); // should be 3
Writeln(Ceil(-4.0)); // should be -4
end.

#### frexp

Declaration:
  Procedure frexp(x : float;var mantissa : float; var exponent : integer);
Description:
  Frexp returns the mantissa and exponent of it’s argument x in mantissa and exponent.
Errors:
  None
See also:

Listing: mathex/ex14.pp

Program Example14;
{ Program to demonstrate the frexp function. }
Uses math;
Procedure dofrexp(Const X : extended);
var man : extended;
exp: longint;
begin
man:=0;
exp:=0;
frexp(x,man,exp);
write(x,' has ');
Writeln('mantissa ',man,' and exponent ',exp);
end;
begin
// dofrexp(1.00);
dofrexp(1.02e-1);
dofrexp(1.03e-2);
dofrexp(1.02e1);
dofrexp(1.03e2);
end.

#### gradtodeg

Declaration:
  Function gradtodeg(grad : float) : float;
Description:
  Gradtodeg converts its argument grad (an angle in grads) to degrees.

  (100 grad is 90 degrees)

Errors:
  None.
See also:
  cycletorad (461), degtograd (462), radtodeg (482), radtograd (482), radtocycle (481), gradtorad (465)

Listing: mathex/ex15.pp

Program Example15;
{ Program to demonstrate the gradtodeg function. }
Uses math;
begin
writeln(gradtodeg(100));
writeln(gradtodeg(200));
writeln(gradtodeg(300));
end.

#### gradtorad

Declaration:
  Function gradtorad(grad : float) : float;
Description:
  Gradtorad converts its argument grad (an angle in grads) to radians.

  (200 grad is pi degrees).

Errors:
  None.
See also:
  cycletorad (461), degtograd (462), radtodeg (482), radtograd (482), radtocycle (481), gradtodeg (465)

Listing: mathex/ex16.pp

Program Example16;
{ Program to demonstrate the gradtorad function. }
Uses math;
begin
writeln(gradtorad(100));
writeln(gradtorad(200));
writeln(gradtorad(300));
end.

#### hypot

Declaration:
  Function hypot(x,y : float) : float;
Description:
  Hypot returns the hypotenuse of the triangle where the sides adjacent to the square angle have lengths x and y.

  The function uses Pythagoras’ rule for this.

Errors:
  None.
See also:

Listing: mathex/ex17.pp

Program Example17;
{ Program to demonstrate the hypot function. }
Uses math;
begin
Writeln(hypot(3,4)); // should be 5
end.

#### intpower

Declaration:
  Function intpower(base : float;exponent : longint) : float;
Description:
  Intpower returns base to the power exponent, where exponent is an integer value.
Errors:
  If base is zero and the exponent is negative, then an overflow error will occur.
See also:
  power (480)

Listing: mathex/ex18.pp

Program Example18;
{ Program to demonstrate the intpower function. }
Uses math;
Procedure DoIntpower (X : extended; Pow : Integer);
begin
writeln(X:8:4,'^',Pow:2,' = ',intpower(X,pow):8:4);
end;
begin
dointpower(0.0,0);
dointpower(1.0,0);
dointpower(2.0,5);
dointpower(4.0,3);
dointpower(2.0,-1);
dointpower(2.0,-2);
dointpower(-2.0,4);
dointpower(-4.0,3);
end.

#### ldexp

Declaration:
  Function ldexp(x : float;p : longint) : float;
Description:
  Ldexp returns 2px.
Errors:
  None.
See also:
  lnxp1 (468), log10 (468),log2 (469),logn (470)

Listing: mathex/ex19.pp

Program Example19;
{ Program to demonstrate the ldexp function. }
Uses math;
begin
writeln(ldexp(2,4):8:4);
writeln(ldexp(0.5,3):8:4);
end.

#### lnxp1

Declaration:
  Function lnxp1(x : float) : float;
Description:
  Lnxp1 returns the natural logarithm of 1+X. The result is more precise for small values of x. x should be larger than -1.
Errors:
  If x < -1 then an EInvalidArgument exception will be raised.
See also:
  ldexp (467), log10 (468),log2 (469),logn (470)

Listing: mathex/ex20.pp

Program Example20;
{ Program to demonstrate the lnxp1 function. }
Uses math;
begin
writeln(lnxp1(0));
writeln(lnxp1(0.5));
writeln(lnxp1(1));
end.

#### log10

Declaration:
  Function log10(x : float) : float;
Description:
  Log10 returns the 10-base logarithm of X.
Errors:
  If x is less than or equal to 0 an ’invalid fpu operation’ error will occur.
See also:
  ldexp (467), lnxp1 (468),log2 (469),logn (470)

Listing: mathex/ex21.pp

Program Example21;
{ Program to demonstrate the log10 function. }
Uses math;
begin
Writeln(Log10(10):8:4);
Writeln(Log10(100):8:4);
Writeln(Log10(1000):8:4);
Writeln(Log10(1):8:4);
Writeln(Log10(0.1):8:4);
Writeln(Log10(0.01):8:4);
Writeln(Log10(0.001):8:4);
end.

#### log2

Declaration:
  Function log2(x : float) : float;
Description:
  Log2 returns the 2-base logarithm of X.
Errors:
  If x is less than or equal to 0 an ’invalid fpu operation’ error will occur.
See also:
  ldexp (467), lnxp1 (468),log10 (468),logn (470)

Listing: mathex/ex22.pp

Program Example22;
{ Program to demonstrate the log2 function. }
Uses math;
begin
Writeln(Log2(2):8:4);
Writeln(Log2(4):8:4);
Writeln(Log2(8):8:4);
Writeln(Log2(1):8:4);
Writeln(Log2(0.5):8:4);
Writeln(Log2(0.25):8:4);
Writeln(Log2(0.125):8:4);
end.

#### logn

Declaration:
  Function logn(n,x : float) : float;
Description:
  Logn returns the n-base logarithm of X.
Errors:
  If x is less than or equal to 0 an ’invalid fpu operation’ error will occur.
See also:
  ldexp (467), lnxp1 (468),log10 (468),log2 (469)

Listing: mathex/ex23.pp

Program Example23;
{ Program to demonstrate the logn function. }
Uses math;
begin
Writeln(Logn(3,4):8:4);
Writeln(Logn(2,4):8:4);
Writeln(Logn(6,9):8:4);
Writeln(Logn(exp(1),exp(1)):8:4);
Writeln(Logn(0.5,1):8:4);
Writeln(Logn(0.25,3):8:4);
Writeln(Logn(0.125,5):8:4);
end.

#### max

Declaration:
  Function max(Int1,Int2:Cardinal):Cardinal; Function max(Int1,Int2:Integer):Integer;
Description:
  Max returns the maximum of Int1 and Int2.
Errors:
  None.
See also:
  min (475), maxIntValue (471), maxvalue (472)

Listing: mathex/ex24.pp

Program Example24;
{ Program to demonstrate the max function. }
Uses math;
Var
A,B : Cardinal;
begin
A:=1;b:=2;
writeln(max(a,b));
end.

#### maxIntValue

Declaration:
  function MaxIntValue(const Data: array of Integer): Integer;
Description:
  MaxIntValue returns the largest integer out of the Data array.

  This function is provided for Delphicompatibility, use the maxvalue (472) function instead.

Errors:
  None.
See also:
  maxvalue (472), minvalue (476), minIntValue (475)

Listing: mathex/ex25.pp

Program Example25;
{ Program to demonstrate the MaxIntValue function. }
{ Make sore integer is 32 bit}
{$mode objfpc}
Uses math;
Type
TExArray = Array[1..100] of Integer;
Var
I : Integer;
ExArray : TExArray;
begin
Randomize;
for I:=1 to 100 do
ExArray[i]:=Random(I)-Random(100);
Writeln(MaxIntValue(ExArray));
end.

#### maxvalue

Declaration:
  Function maxvalue(const data : array of float) : float; Function maxvalue(const data : array of Integer) : Integer; Function maxvalue(const data : PFloat; Const N : Integer) : float; Function maxvalue(const data : PInteger; Const N : Integer) : Integer;
Description:
  Maxvalue returns the largest value in the data array with integer or float values. The return value has the same type as the elements of the array.

  The third and fourth forms accept a pointer to an array of N integer or float values.

Errors:
  None.
See also:
  maxIntValue (471), minvalue (476), minIntValue (475)

Listing: mathex/ex26.pp

Program Example26;
{ Program to demonstrate the MaxValue function. }
{ Make sore integer is 32 bit}
{$mode objfpc}
Uses math;
Type
TExFloatArray = Array[1..100] of Float;
TExIntArray = Array[1..100] of Integer;
Var
I : Integer;
ExFloatArray : TExFloatArray;
ExIntArray : TExIntArray;
AFLoatArray : PFLoat;
AIntArray : PInteger;
begin
Randomize;
AFloatArray:=@ExFloatArray[1];
AIntArray:=@ExIntArray[1];
for I:=1 to 100 do
ExFloatArray[i]:=(Random-Random)*100;
for I:=1 to 100 do
ExIntArray[i]:=Random(I)-Random(100);
Writeln('Max Float : ',MaxValue(ExFloatArray):8:4);
Writeln('Max Float (b) : ',MaxValue(AFloatArray,100):8:4);
Writeln('Max Integer : ',MaxValue(ExIntArray):8);
Writeln('Max Integer (b) : ',MaxValue(AIntArray,100):8);
end.

#### mean

Declaration:
  Function mean(const data : array of float) : float; Function mean(const data : PFloat; Const N : longint) : float;
Description:
  Mean returns the average value of data.

  The second form accepts a pointer to an array of N values.

Errors:
  None.
See also:
  meanandstddev (474), momentskewkurtosis (477), sum (486)

Listing: mathex/ex27.pp

Program Example27;
{ Program to demonstrate the Mean function. }
Uses math;
Type
TExArray = Array[1..100] of Float;
Var
I : Integer;
ExArray : TExArray;
begin
Randomize;
for I:=1 to 100 do
ExArray[i]:=(Random-Random)*100;
Writeln('Max : ',MaxValue(ExArray):8:4);
Writeln('Min : ',MinValue(ExArray):8:4);
Writeln('Mean : ',Mean(ExArray):8:4);
Writeln('Mean (b) : ',Mean(@ExArray[1],100):8:4);
end.

#### meanandstddev

Declaration:
  Procedure meanandstddev(const data : array of float; var mean,stddev : float); procedure meanandstddev(const data : PFloat; Const N : Longint;var mean,stddev : float);
Description:
  meanandstddev calculates the mean and standard deviation of data and returns the result in mean and stddev, respectively. Stddev is zero if there is only one value.

  The second form accepts a pointer to an array of N values.

Errors:
  None.
See also:
  mean (473),sum (486), sumofsquares (487), momentskewkurtosis (477)

Listing: mathex/ex28.pp

Program Example28;
{ Program to demonstrate the Meanandstddev function. }
Uses math;
Type
TExArray = Array[1..100] of Extended;
Var
I : Integer;
ExArray : TExArray;
Mean,stddev : Extended;
begin
Randomize;
for I:=1 to 100 do
ExArray[i]:=(Random-Random)*100;
MeanAndStdDev(ExArray,Mean,StdDev);
Writeln('Mean : ',Mean:8:4);
Writeln('StdDev : ',StdDev:8:4);
MeanAndStdDev(@ExArray[1],100,Mean,StdDev);
Writeln('Mean (b) : ',Mean:8:4);
Writeln('StdDev (b) : ',StdDev:8:4);
end.

#### min

Declaration:
  Function min(Int1,Int2:Cardinal):Cardinal; Function min(Int1,Int2:Integer):Integer;
Description:
  min returns the smallest value of Int1 and Int2;
Errors:
  None.
See also:
  max (470)

Listing: mathex/ex29.pp

Program Example29;
{ Program to demonstrate the min function. }
Uses math;
Var
A,B : Cardinal;
begin
A:=1;b:=2;
writeln(min(a,b));
end.

#### minIntValue

Declaration:
  Function minIntValue(const Data: array of Integer): Integer;
Description:
  MinIntvalue returns the smallest value in the Data array.

  This function is provided for Delphicompatibility, use minvalue instead.

Errors:
  None
See also:
  minvalue (476), maxIntValue (471), maxvalue (472)

Listing: mathex/ex30.pp

Program Example30;
{ Program to demonstrate the MinIntValue function. }
{ Make sore integer is 32 bit}
{$mode objfpc}
Uses math;
Type
TExArray = Array[1..100] of Integer;
Var
I : Integer;
ExArray : TExArray;
begin
Randomize;
for I:=1 to 100 do
ExArray[i]:=Random(I)-Random(100);
Writeln(MinIntValue(ExArray));
end.

#### minvalue

Declaration:
  Function minvalue(const data : array of float) : float; Function minvalue(const data : array of Integer) : Integer; Function minvalue(const data : PFloat; Const N : Integer) : float; Function minvalue(const data : PInteger; Const N : Integer) : Integer;
Description:
  Minvalue returns the smallest value in the data array with integer or float values. The return value has the same type as the elements of the array.

  The third and fourth forms accept a pointer to an array of N integer or float values.

Errors:
  None.
See also:
  maxIntValue (471), maxvalue (472), minIntValue (475)

Listing: mathex/ex31.pp

Program Example26;
{ Program to demonstrate the MinValue function. }
{ Make sore integer is 32 bit}
{$mode objfpc}
Uses math;
Type
TExFloatArray = Array[1..100] of Float;
TExIntArray = Array[1..100] of Integer;
Var
I : Integer;
ExFloatArray : TExFloatArray;
AFloatArray : PFloat;
ExIntArray : TExIntArray;
AintArray : PInteger;
begin
Randomize;
AFloatArray:=@ExFloatArray[0];
AIntArray:=@ExIntArray[0];
for I:=1 to 100 do
ExFloatArray[i]:=(Random-Random)*100;
for I:=1 to 100 do
ExIntArray[i]:=Random(I)-Random(100);
Writeln('Min Float : ',MinValue(ExFloatArray):8:4);
Writeln('Min Float (b) : ',MinValue(AFloatArray,100):8:4);
Writeln('Min Integer : ',MinValue(ExIntArray):8);
Writeln('Min Integer (b) : ',MinValue(AintArray,100):8);
end.

#### momentskewkurtosis

Declaration:
  procedure momentskewkurtosis(const data : array of float; var m1,m2,m3,m4,skew,kurtosis : float); procedure momentskewkurtosis(const data : PFloat; Const N : Integer; var m1,m2,m3,m4,skew,kurtosis : float);
Description:
  momentskewkurtosis calculates the 4 first moments of the distribution of valuesin data and returns them in m1,m2,m3 and m4, as well as the skew and kurtosis.
Errors:
  None.
See also:
  mean (473), meanandstddev (474)

Listing: mathex/ex32.pp

Program Example32;
{ Program to demonstrate the momentskewkurtosis function. }
Uses math;
Var
DistArray : Array[1..1000] of float;
I : longint;
m1,m2,m3,m4,skew,kurtosis : float;
begin
randomize;
for I:=1 to 1000 do
distarray[i]:=random;
momentskewkurtosis(DistArray,m1,m2,m3,m4,skew,kurtosis);
Writeln ('1st moment : ',m1:8:6);
Writeln ('2nd moment : ',m2:8:6);
Writeln ('3rd moment : ',m3:8:6);
Writeln ('4th moment : ',m4:8:6);
Writeln ('Skew : ',skew:8:6);
Writeln ('kurtosis : ',kurtosis:8:6);
end.

#### norm

Declaration:
  Function norm(const data : array of float) : float; Function norm(const data : PFloat; Const N : Integer) : float;
Description:
  Norm calculates the Euclidian norm of the array of data. This equals sqrt(sumofsquares(data)).

  The second form accepts a pointer to an array of N values.

Errors:
  None.
See also:
  sumofsquares (487)

Listing: mathex/ex33.pp

Program Example33;
{ Program to demonstrate the norm function. }
Uses math;
Type
TVector = Array[1..10] of Float;
Var
AVector : Tvector;
I : longint;
begin
for I:=1 to 10 do
Avector[i]:=Random;
Writeln(Norm(AVector));
end.

#### popnstddev

Declaration:
  Function popnstddev(const data : array of float) : float; Function popnstddev(const data : PFloat; Const N : Integer) : float;
Description:
  Popnstddev returns the square root of the population variance of the values in the Data array. It returns zero if there is only one value.

  The second form of this function accepts a pointer to an array of N values.

Errors:
  None.
See also:
  popnvariance (480), mean (473), meanandstddev (474), stddev (485), momentskewkurtosis (477)

Listing: mathex/ex35.pp

Program Example35;
{ Program to demonstrate the PopnStdDev function. }
Uses Math;
Type
TExArray = Array[1..100] of Float;
Var
I : Integer;
ExArray : TExArray;
begin
Randomize;
for I:=1 to 100 do
ExArray[i]:=(Random-Random)*100;
Writeln('Max : ',MaxValue(ExArray):8:4);
Writeln('Min : ',MinValue(ExArray):8:4);
Writeln('Pop. stddev. : ',PopnStdDev(ExArray):8:4);
Writeln('Pop. stddev. (b) : ',PopnStdDev(@ExArray[1],100):8:4);
end.

#### popnvariance

Declaration:
  Function popnvariance(const data : array of float) : float; Function popnvariance(const data : PFloat; Const N : Integer) : float;
Description:
  Popnvariance returns the square root of the population variance of the values in the Data array. It returns zero if there is only one value.

  The second form of this function accepts a pointer to an array of N values.

Errors:
  None.
See also:
  popnstddev (479), mean (473), meanandstddev (474), stddev (485), momentskewkurtosis (477)

Listing: mathex/ex36.pp

Program Example36;
{ Program to demonstrate the PopnVariance function. }
Uses math;
Type
TExArray = Array[1..100] of Float;
Var
I : Integer;
ExArray : TExArray;
begin
Randomize;
for I:=1 to 100 do
ExArray[i]:=(Random-Random)*100;
Writeln('Max : ',MaxValue(ExArray):8:4);
Writeln('Min : ',MinValue(ExArray):8:4);
Writeln('Pop. var. : ',PopnVariance(ExArray):8:4);
Writeln('Pop. var. (b) : ',PopnVariance(@ExArray[1],100):8:4);
end.

#### power

Declaration:
  Function power(base,exponent : float) : float;
Description:
  power raises base to the power power. This is equivalent to exp(power*ln(base)). Therefore base should be non-negative.
Errors:
  None.
See also:
  intpower (467)

Listing: mathex/ex34.pp

Program Example34;
{ Program to demonstrate the power function. }
Uses Math;
procedure dopower(x,y : float);
begin
writeln(x:8:6,'^',y:8:6,' = ',power(x,y):8:6)
end;
begin
dopower(2,2);
dopower(2,-2);
dopower(2,0.0);
end.

#### radtocycle

Declaration:
  Function radtocycle(rad : float) : float;
Description:
  Radtocycle converts its argument rad (an angle expressed in radians) to an angle in cycles.

  (1 cycle equals 2 pi radians)

Errors:
  None.
See also:
  degtograd (462), degtorad (463), radtodeg (482), radtograd (482), cycletorad (461)

Listing: mathex/ex37.pp

Program Example37;
{ Program to demonstrate the radtocycle function. }
Uses math;
begin
writeln(radtocycle(2*pi):8:6);
writeln(radtocycle(pi):8:6);
writeln(radtocycle(pi/2):8:6);
end.

#### radtodeg

Declaration:
  Function radtodeg(rad : float) : float;
Description:
  Radtodeg converts its argument rad (an angle expressed in radians) to an angle in degrees.

  (180 degrees equals pi radians)

Errors:
  None.
See also:
  degtograd (462), degtorad (463), radtocycle (481), radtograd (482), cycletorad (461)

Listing: mathex/ex38.pp

Program Example38;
{ Program to demonstrate the radtodeg function. }
Uses math;
begin
writeln(radtodeg(2*pi):8:6);
writeln(radtodeg(pi):8:6);
writeln(radtodeg(pi/2):8:6);
end.

#### radtograd

Declaration:
  Function radtograd(rad : float) : float;
Description:
  Radtodeg converts its argument rad (an angle expressed in radians) to an angle in grads.

  (200 grads equals pi radians)

Errors:
  None.
See also:
  degtograd (462), degtorad (463), radtocycle (481), radtodeg (482), cycletorad (461)

Listing: mathex/ex39.pp

Program Example39;
{ Program to demonstrate the radtograd function. }
Uses math;
begin
writeln(radtograd(2*pi):8:6);
writeln(radtograd(pi):8:6);
writeln(radtograd(pi/2):8:6);
end.

#### randg

Declaration:
  Function randg(mean,stddev : float) : float;
Description:
  randg returns a random number which - when produced in large quantities - has a Gaussian distribution with mean mean and standarddeviation stddev.
Errors:
  None.
See also:
  mean (473), stddev (485), meanandstddev (474)

Listing: mathex/ex40.pp

Program Example40;
{ Program to demonstrate the randg function. }
Uses Math;
Type
TExArray = Array[1..10000] of Float;
Var
I : Integer;
ExArray : TExArray;
Mean,stddev : Float;
begin
Randomize;
for I:=1 to 10000 do
ExArray[i]:=Randg(1,0.2);
MeanAndStdDev(ExArray,Mean,StdDev);
Writeln('Mean : ',Mean:8:4);
Writeln('StdDev : ',StdDev:8:4);
end.

#### sincos

Declaration:
  Procedure sincos(theta : float;var sinus,cosinus : float);
Description:
  Sincos calculates the sine and cosine of the angle theta, and returns the result in sinus and cosinus.

  On Intel hardware, This calculation will be faster than making 2 calls to clculatet he sine and cosine separately.

Errors:
  None.
See also:
  arcsin (457), arccos (456).

Listing: mathex/ex41.pp

Program Example41;
{ Program to demonstrate the sincos function. }
Uses math;
Procedure dosincos(Angle : Float);
Var
Sine,Cosine : Float;
begin
sincos(angle,sine,cosine);
Write('Angle : ',Angle:8:6);
Write(' Sine :',sine:8:6);
Write(' Cosine :',cosine:8:6);
end;
begin
dosincos(pi);
dosincos(pi/2);
dosincos(pi/3);
dosincos(pi/4);
dosincos(pi/6);
end.

#### sinh

Declaration:
  Function sinh(x : float) : float;
Description:
  Sinh returns the hyperbolic sine of its argument x.
Errors:
See also:
  cosh (460), arsinh (459), tanh (489), artanh (459)

Listing: mathex/ex42.pp

Program Example42;
{ Program to demonstrate the sinh function. }
Uses math;
begin
writeln(sinh(0));
writeln(sinh(1));
writeln(sinh(-1));
end.

#### stddev

Declaration:
  Function stddev(const data : array of float) : float; Function stddev(const data : PFloat; Const N : Integer) : float;
Description:
  Stddev returns the standard deviation of the values in Data. It returns zero if there is only one value.

  The second form of the function accepts a pointer to an array of N values.

Errors:
  None.
See also:
  mean (473), meanandstddev (474), variance (491), totalvariance (490)

Listing: mathex/ex43.pp

Program Example40;
{ Program to demonstrate the stddev function. }
Uses Math;
Type
TExArray = Array[1..10000] of Float;
Var
I : Integer;
ExArray : TExArray;
begin
Randomize;
for I:=1 to 10000 do
ExArray[i]:=Randg(1,0.2);
Writeln('StdDev : ',StdDev(ExArray):8:4);
Writeln('StdDev (b) : ',StdDev(@ExArray[0],10000):8:4);
end.

#### sum

Declaration:
  Function sum(const data : array of float) : float; Function sum(const data : PFloat; Const N : Integer) : float;
Description:
  Sum returns the sum of the values in the data array.

  The second form of the function accepts a pointer to an array of N values.

Errors:
  None.
See also:
  sumofsquares (487), sumsandsquares (488), totalvariance (490) , variance (491)

Listing: mathex/ex44.pp

Program Example44;
{ Program to demonstrate the Sum function. }
Uses math;
Type
TExArray = Array[1..100] of Float;
Var
I : Integer;
ExArray : TExArray;
begin
Randomize;
for I:=1 to 100 do
ExArray[i]:=(Random-Random)*100;
Writeln('Max : ',MaxValue(ExArray):8:4);
Writeln('Min : ',MinValue(ExArray):8:4);
Writeln('Sum : ',Sum(ExArray):8:4);
Writeln('Sum (b) : ',Sum(@ExArray[1],100):8:4);
end.

#### sumofsquares

Declaration:
  Function sumofsquares(const data : array of float) : float; Function sumofsquares(const data : PFloat; Const N : Integer) : float;
Description:
  Sumofsquares returns the sum of the squares of the values in the data array.

  The second form of the function accepts a pointer to an array of N values.

Errors:
  None.
See also:
  sum (486), sumsandsquares (488), totalvariance (490) , variance (491)

Listing: mathex/ex45.pp

Program Example45;
{ Program to demonstrate the SumOfSquares function. }
Uses math;
Type
TExArray = Array[1..100] of Float;
Var
I : Integer;
ExArray : TExArray;
begin
Randomize;
for I:=1 to 100 do
ExArray[i]:=(Random-Random)*100;
Writeln('Max : ',MaxValue(ExArray):8:4);
Writeln('Min : ',MinValue(ExArray):8:4);
Writeln('Sum squares : ',SumOfSquares(ExArray):8:4);
Writeln('Sum squares (b) : ',SumOfSquares(@ExArray[1],100):8:4);
end.

#### sumsandsquares

Declaration:
  Procedure sumsandsquares(const data : array of float; var sum,sumofsquares : float); Procedure sumsandsquares(const data : PFloat; Const N : Integer; var sum,sumofsquares : float);
Description:
  sumsandsquares calculates the sum of the values and the sum of the squares of the values in the data array and returns the results in sum and sumofsquares.

  The second form of the function accepts a pointer to an array of N values.

Errors:
  None.
See also:
  sum (486), sumofsquares (487), totalvariance (490) , variance (491)

Listing: mathex/ex46.pp

Program Example45;
{ Program to demonstrate the SumOfSquares function. }
Uses math;
Type
TExArray = Array[1..100] of Float;
Var
I : Integer;
ExArray : TExArray;
s,ss : float;
begin
Randomize;
for I:=1 to 100 do
ExArray[i]:=(Random-Random)*100;
Writeln('Max : ',MaxValue(ExArray):8:4);
Writeln('Min : ',MinValue(ExArray):8:4);
SumsAndSquares(ExArray,S,SS);
Writeln('Sum : ',S:8:4);
Writeln('Sum squares : ',SS:8:4);
SumsAndSquares(@ExArray[1],100,S,SS);
Writeln('Sum (b) : ',S:8:4);
Writeln('Sum squares (b) : ',SS:8:4);
end.

#### tan

Declaration:
  Function tan(x : float) : float;
Description:
  Tan returns the tangent of x.
Errors:
  If x (normalized) is pi/2 or 3pi/2 then an overflow will occur.
See also:
  tanh (489), arcsin (457), sincos (484), arccos (456)

Listing: mathex/ex47.pp

Program Example47;
{ Program to demonstrate the Tan function. }
Uses math;
Procedure DoTan(Angle : Float);
begin
Write('Angle : ',RadToDeg(Angle):8:6);
Writeln(' Tangent : ',Tan(Angle):8:6);
end;
begin
DoTan(0);
DoTan(Pi);
DoTan(Pi/3);
DoTAn(Pi/4);
DoTan(Pi/6);
end.

#### tanh

Declaration:
  Function tanh(x : float) : float;
Description:
  Tanh returns the hyperbolic tangent of x.
Errors:
  None.
See also:
  arcsin (457), sincos (484), arccos (456)

Listing: mathex/ex48.pp

Program Example48;
{ Program to demonstrate the Tanh function. }
Uses math;
begin
writeln(tanh(0));
writeln(tanh(1));
writeln(tanh(-1));
end.

#### totalvariance

Declaration:
  Function totalvariance(const data : array of float) : float; Function totalvariance(const data : PFloat; Const N : Integer) : float;
Description:
  TotalVariance returns the total variance of the values in the data array. It returns zero if there is only one value.

  The second form of the function accepts a pointer to an array of N values.

Errors:
  None.
See also:
  variance (491), stddev (485), mean (473)

Listing: mathex/ex49.pp

Program Example49;
{ Program to demonstrate the TotalVariance function. }
Uses math;
Type
TExArray = Array[1..100] of Float;
Var
I : Integer;
ExArray : TExArray;
TV : float;
begin
Randomize;
for I:=1 to 100 do
ExArray[i]:=(Random-Random)*100;
TV:=TotalVariance(ExArray);
Writeln('Total variance : ',TV:8:4);
TV:=TotalVariance(@ExArray[1],100);
Writeln('Total Variance (b) : ',TV:8:4);
end.

#### variance

Declaration:
  Function variance(const data : array of float) : float; Function variance(const data : PFloat; Const N : Integer) : float;
Description:
  Variance returns the variance of the values in the data array. It returns zero if there is only one value.

  The second form of the function accepts a pointer to an array of N values.

Errors:
  None.
See also:
  totalvariance (490), stddev (485), mean (473)

Listing: mathex/ex50.pp

Program Example50;
{ Program to demonstrate the Variance function. }
Uses math;
Type
TExArray = Array[1..100] of Float;
Var
I : Integer;
ExArray : TExArray;
V : float;
begin
Randomize;
for I:=1 to 100 do
ExArray[i]:=(Random-Random)*100;
V:=Variance(ExArray);
Writeln('Variance : ',V:8:4);
V:=Variance(@ExArray[1],100);
Writeln('Variance (b) : ',V:8:4);
end.

[prev] [prev-tail] [front] [up]