math.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. This unit is an equivalent to the Delphi math unit
  14. (with some improvements)
  15. About assembler usage:
  16. ----------------------
  17. I used as few as possible assembler to allow an easy port
  18. to other processors. Today, I think it's wasted time to write
  19. assembler because different versions of a family of processors
  20. need different implementations.
  21. To improve performance, I changed all integer arguments and
  22. functions results to longint, because 16 bit instructions are
  23. lethal for a modern intel processor.
  24. (FK)
  25. What's to do:
  26. o a lot of function :), search for !!!!
  27. o some statistical functions
  28. o all financial functions
  29. o optimizations
  30. }
  31. unit math;
  32. interface
  33. {$MODE objfpc}
  34. uses
  35. sysutils;
  36. type
  37. { the original delphi functions use extended as argument, }
  38. { but I would prefer double, because 8 bytes is a very }
  39. { natural size for the processor }
  40. { WARNING : changing float type will }
  41. { break all assembler code PM }
  42. float = extended;
  43. PFloat = ^Float;
  44. PInteger = ^Integer;
  45. tpaymenttime = (ptendofperiod,ptstartofperiod);
  46. einvalidargument = class(ematherror);
  47. { Min/max determination }
  48. function MinIntValue(const Data: array of Integer): Integer;
  49. function MaxIntValue(const Data: array of Integer): Integer;
  50. { Extra, not present in Delphi, but used frequently }
  51. function Min(Int1,Int2:Integer):Integer;
  52. function Min(Int1,Int2:Cardinal):Cardinal;
  53. function Max(Int1,Int2:Integer):Integer;
  54. function Max(Int1,Int2:Cardinal):Cardinal;
  55. { angle conversion }
  56. function degtorad(deg : float) : float;
  57. function radtodeg(rad : float) : float;
  58. function gradtorad(grad : float) : float;
  59. function radtograd(rad : float) : float;
  60. function degtograd(deg : float) : float;
  61. function gradtodeg(grad : float) : float;
  62. { one cycle are 2*Pi rad }
  63. function cycletorad(cycle : float) : float;
  64. function radtocycle(rad : float) : float;
  65. { trigoniometric functions }
  66. function tan(x : float) : float;
  67. function cotan(x : float) : float;
  68. procedure sincos(theta : float;var sinus,cosinus : float);
  69. { inverse functions }
  70. function arccos(x : float) : float;
  71. function arcsin(x : float) : float;
  72. { calculates arctan(x/y) and returns an angle in the correct quadrant }
  73. function arctan2(x,y : float) : float;
  74. { hyperbolic functions }
  75. function cosh(x : float) : float;
  76. function sinh(x : float) : float;
  77. function tanh(x : float) : float;
  78. { area functions }
  79. { delphi names: }
  80. function arccosh(x : float) : float;
  81. function arcsinh(x : float) : float;
  82. function arctanh(x : float) : float;
  83. { IMHO the function should be called as follows (FK) }
  84. function arcosh(x : float) : float;
  85. function arsinh(x : float) : float;
  86. function artanh(x : float) : float;
  87. { triangle functions }
  88. { returns the length of the hypotenuse of a right triangle }
  89. { if x and y are the other sides }
  90. function hypot(x,y : float) : float;
  91. { logarithm functions }
  92. function log10(x : float) : float;
  93. function log2(x : float) : float;
  94. function logn(n,x : float) : float;
  95. { returns natural logarithm of x+1 }
  96. function lnxp1(x : float) : float;
  97. { exponential functions }
  98. function power(base,exponent : float) : float;
  99. { base^exponent }
  100. function intpower(base : float;exponent : longint) : float;
  101. { number converting }
  102. { rounds x towards positive infinity }
  103. function ceil(x : float) : longint;
  104. { rounds x towards negative infinity }
  105. function floor(x : float) : longint;
  106. { misc. functions }
  107. { splits x into mantissa and exponent (to base 2) }
  108. procedure frexp(x : float;var mantissa,exponent : float);
  109. { returns x*(2^p) }
  110. function ldexp(x : float;p : longint) : float;
  111. { statistical functions }
  112. function mean(const data : array of float) : float;
  113. function sum(const data : array of float) : float;
  114. function mean(const data : PFloat; Const N : longint) : float;
  115. function sum(const data : PFloat; Const N : Longint) : float;
  116. function sumofsquares(const data : array of float) : float;
  117. function sumofsquares(const data : PFloat; Const N : Integer) : float;
  118. { calculates the sum and the sum of squares of data }
  119. procedure sumsandsquares(const data : array of float;
  120. var sum,sumofsquares : float);
  121. procedure sumsandsquares(const data : PFloat; Const N : Integer;
  122. var sum,sumofsquares : float);
  123. function minvalue(const data : array of float) : float;
  124. function minvalue(const data : array of integer) : Integer;
  125. function minvalue(const data : PFloat; Const N : Integer) : float;
  126. function MinValue(const Data : PInteger; Const N : Integer): Integer;
  127. function maxvalue(const data : array of float) : float;
  128. function maxvalue(const data : array of integer) : Integer;
  129. function maxvalue(const data : PFloat; Const N : Integer) : float;
  130. function maxvalue(const data : PInteger; Const N : Integer) : Integer;
  131. { calculates the standard deviation }
  132. function stddev(const data : array of float) : float;
  133. { calculates the mean and stddev }
  134. procedure meanandstddev(const data : array of float;
  135. var mean,stddev : float);
  136. procedure meanandstddev(const data : PFloat;
  137. Const N : Longint;var mean,stddev : float);
  138. function variance(const data : array of float) : float;
  139. function totalvariance(const data : array of float) : float;
  140. function variance(const data : PFloat; Const N : Integer) : float;
  141. function totalvariance(const data : PFloat; Const N : Integer) : float;
  142. { returns random values with gaussian distribution }
  143. function randg(mean,stddev : float) : float;
  144. { I don't know what the following functions do: }
  145. function popnstddev(const data : array of float) : float;
  146. function popnstddev(const data : PFloat; Const N : Integer) : float;
  147. function popnvariance(const data : PFloat; Const N : Integer) : float;
  148. function popnvariance(const data : array of float) : float;
  149. procedure momentskewkurtosis(const data : array of float;
  150. var m1,m2,m3,m4,skew,kurtosis : float);
  151. procedure momentskewkurtosis(const data : PFloat; Const N : Integer;
  152. var m1,m2,m3,m4,skew,kurtosis : float);
  153. { geometrical function }
  154. { returns the euclidean L2 norm }
  155. function norm(const data : array of float) : float;
  156. function norm(const data : PFloat; Const N : Integer) : float;
  157. implementation
  158. ResourceString
  159. SMathError = 'Math Error : %s';
  160. SInvalidArgument = 'Invalid argument';
  161. Procedure DoMathError(Const S : String);
  162. begin
  163. Raise EMathError.CreateFmt(SMathError,[S]);
  164. end;
  165. Procedure InvalidArgument;
  166. begin
  167. Raise EInvalidArgument.Create(SInvalidArgument);
  168. end;
  169. function degtorad(deg : float) : float;
  170. begin
  171. degtorad:=deg*(pi/180.0);
  172. end;
  173. function radtodeg(rad : float) : float;
  174. begin
  175. radtodeg:=rad*(180.0/pi);
  176. end;
  177. function gradtorad(grad : float) : float;
  178. begin
  179. gradtorad:=grad*(pi/200.0);
  180. end;
  181. function radtograd(rad : float) : float;
  182. begin
  183. radtograd:=rad*(200.0/pi);
  184. end;
  185. function degtograd(deg : float) : float;
  186. begin
  187. degtograd:=deg*(200.0/180.0);
  188. end;
  189. function gradtodeg(grad : float) : float;
  190. begin
  191. gradtodeg:=grad*(180.0/200.0);
  192. end;
  193. function cycletorad(cycle : float) : float;
  194. begin
  195. cycletorad:=(2*pi)*cycle;
  196. end;
  197. function radtocycle(rad : float) : float;
  198. begin
  199. { avoid division }
  200. radtocycle:=rad*(1/(2*pi));
  201. end;
  202. function tan(x : float) : float;
  203. begin
  204. Tan:=Sin(x)/Cos(x)
  205. end;
  206. function cotan(x : float) : float;
  207. begin
  208. cotan:=Cos(X)/Sin(X);
  209. end;
  210. procedure sincos(theta : float;var sinus,cosinus : float);
  211. begin
  212. {$ifndef i386}
  213. sinus:=sin(theta);
  214. cosinus:=cos(theta);
  215. {$else}
  216. asm
  217. fldl theta
  218. fsincos
  219. fwait
  220. movl cosinus,%eax
  221. fstpl (%eax)
  222. movl sinus,%eax
  223. fstpl (%eax)
  224. end;
  225. {$endif}
  226. end;
  227. { Sign, ArcSin and ArcCos from Arjan van Dijk ([email protected]) }
  228. function sign(x : float) : float;
  229. begin
  230. if x > 0 then sign := 1.0
  231. else if x < 0 then sign := -1.0
  232. else sign := 0.0;
  233. end;
  234. function arcsin(x : float) : float;
  235. begin
  236. if abs(x) > 1 then InvalidArgument
  237. else if abs(x) < 0.5 then
  238. arcsin := arctan(x/sqrt(1-sqr(x)))
  239. else
  240. arcsin := sign(x) * (pi*0.5 - arctan(sqrt(1 / sqr(x) - 1)));
  241. end;
  242. function Arccos(x : Float) : Float;
  243. begin
  244. arccos := pi*0.5 - arcsin(x);
  245. end;
  246. function arctan2( x,y : float) : float;
  247. {$ifndef i386}
  248. begin
  249. ArcTan2:=ArcTan(x/y);
  250. {$else}
  251. { without the assembler keyword, you have to store the result to }
  252. { __result at the end of the assembler block (JM) }
  253. assembler;
  254. asm
  255. fldt X
  256. fldt Y
  257. fpatan
  258. //leave
  259. // ret $20 This is wrong for 4 byte aligned OS !!
  260. {$endif}
  261. end;
  262. function cosh(x : float) : float;
  263. var
  264. temp : float;
  265. begin
  266. temp:=exp(x);
  267. cosh:=0.5*(temp+1.0/temp);
  268. end;
  269. function sinh(x : float) : float;
  270. var
  271. temp : float;
  272. begin
  273. temp:=exp(x);
  274. sinh:=0.5*(temp-1.0/temp);
  275. end;
  276. Const MaxTanh=5000; { rather arbitrary, but more or less correct }
  277. function tanh(x : float) : float;
  278. var Temp : float;
  279. begin
  280. if x>MaxTanh then exit(1.0)
  281. else if x<-MaxTanh then exit (-1.0);
  282. temp:=exp(-2*x);
  283. tanh:=(1-temp)/(1+temp)
  284. end;
  285. function arccosh(x : float) : float;
  286. begin
  287. arccosh:=arcosh(x);
  288. end;
  289. function arcsinh(x : float) : float;
  290. begin
  291. arcsinh:=arsinh(x);
  292. end;
  293. function arctanh(x : float) : float;
  294. begin
  295. if x>1 then InvalidArgument;
  296. arctanh:=artanh(x);
  297. end;
  298. function arcosh(x : float) : float;
  299. begin
  300. if x<1 then InvalidArgument;
  301. arcosh:=Ln(x+Sqrt(x*x-1));
  302. end;
  303. function arsinh(x : float) : float;
  304. begin
  305. arsinh:=Ln(x+Sqrt(1+x*x));
  306. end;
  307. function artanh(x : float) : float;
  308. begin
  309. If abs(x)>1 then InvalidArgument;
  310. artanh:=(Ln((1+x)/(1-x)))*0.5;
  311. end;
  312. function hypot(x,y : float) : float;
  313. begin
  314. hypot:=Sqrt(x*x+y*y)
  315. end;
  316. function log10(x : float) : float;
  317. begin
  318. log10:=ln(x)/ln(10);
  319. end;
  320. function log2(x : float) : float;
  321. begin
  322. log2:=ln(x)/ln(2)
  323. end;
  324. function logn(n,x : float) : float;
  325. begin
  326. if n<0 then InvalidArgument;
  327. logn:=ln(x)/ln(n);
  328. end;
  329. function lnxp1(x : float) : float;
  330. begin
  331. if x<-1 then
  332. InvalidArgument;
  333. lnxp1:=ln(1+x);
  334. end;
  335. function power(base,exponent : float) : float;
  336. begin
  337. If Exponent=0.0 then
  338. Result:=1.0
  339. else
  340. If base>0.0 then
  341. Power:=exp(exponent * ln (base))
  342. else if base=0.0 then
  343. Result:=0.0
  344. else
  345. InvalidArgument
  346. end;
  347. function intpower(base : float;exponent : longint) : float;
  348. var
  349. i : longint;
  350. begin
  351. i:=abs(exponent);
  352. intpower:=1.0;
  353. while i>0 do
  354. begin
  355. while (i and 1)=0 do
  356. begin
  357. i:=i shr 1;
  358. base:=sqr(base);
  359. end;
  360. i:=i-1;
  361. intpower:=intpower*base;
  362. end;
  363. if exponent<0 then
  364. intpower:=1.0/intpower;
  365. end;
  366. function ceil(x : float) : longint;
  367. begin
  368. Ceil:=Trunc(x);
  369. If Frac(x)>0 then
  370. Ceil:=Ceil+1;
  371. end;
  372. function floor(x : float) : longint;
  373. begin
  374. Floor:=Trunc(x);
  375. If Frac(x)<0 then
  376. Floor := Floor-1;
  377. end;
  378. procedure frexp(x : float;var mantissa,exponent : float);
  379. begin
  380. end;
  381. function ldexp(x : float;p : longint) : float;
  382. begin
  383. ldexp:=x*intpower(2.0,p);
  384. end;
  385. function mean(const data : array of float) : float;
  386. begin
  387. Result:=Mean(@data[0],High(Data)+1);
  388. end;
  389. function mean(const data : PFloat; Const N : longint) : float;
  390. begin
  391. mean:=sum(Data,N);
  392. mean:=mean/N;
  393. end;
  394. function sum(const data : array of float) : float;
  395. begin
  396. Result:=Sum(@Data[0],High(Data)+1);
  397. end;
  398. function sum(const data : PFloat;Const N : longint) : float;
  399. var
  400. i : longint;
  401. begin
  402. sum:=0.0;
  403. for i:=0 to N-1 do
  404. sum:=sum+data[i];
  405. end;
  406. function sumofsquares(const data : array of float) : float;
  407. begin
  408. Result:=sumofsquares(@data[0],High(Data)+1);
  409. end;
  410. function sumofsquares(const data : PFloat; Const N : Integer) : float;
  411. var
  412. i : longint;
  413. begin
  414. sumofsquares:=0.0;
  415. for i:=0 to N-1 do
  416. sumofsquares:=sumofsquares+sqr(data[i]);
  417. end;
  418. procedure sumsandsquares(const data : array of float;
  419. var sum,sumofsquares : float);
  420. begin
  421. sumsandsquares (@Data[0],High(Data)+1,Sum,sumofsquares);
  422. end;
  423. procedure sumsandsquares(const data : PFloat; Const N : Integer;
  424. var sum,sumofsquares : float);
  425. var
  426. i : Integer;
  427. temp : float;
  428. begin
  429. sumofsquares:=0.0;
  430. sum:=0.0;
  431. for i:=0 to N-1 do
  432. begin
  433. temp:=data[i];
  434. sumofsquares:=sumofsquares+sqr(temp);
  435. sum:=sum+temp;
  436. end;
  437. end;
  438. function stddev(const data : array of float) : float;
  439. begin
  440. StdDev:=Sqrt(Variance(Data));
  441. end;
  442. procedure meanandstddev(const data : array of float;
  443. var mean,stddev : float);
  444. begin
  445. Meanandstddev(@Data[0],High(Data)+1,Mean,stddev);
  446. end;
  447. procedure meanandstddev(const data : PFloat;
  448. Const N : Longint;var mean,stddev : float);
  449. Var I : longint;
  450. begin
  451. Mean:=0;
  452. StdDev:=0;
  453. For I:=0 to N-1 do
  454. begin
  455. Mean:=Mean+Data[i];
  456. StdDev:=StdDev+Sqr(Data[i]);
  457. end;
  458. Mean:=Mean/N;
  459. StdDev:=StdDev/sqr(N)-Sqr(Mean);
  460. { // the following depends on the definition of standard deviation...
  461. If N>1 then
  462. StdDev:=Sqrt(Stddev/(N-1))
  463. else
  464. StdDev:=0;
  465. }
  466. end;
  467. function variance(const data : array of float) : float;
  468. begin
  469. Variance:=Variance(@Data[0],High(Data)+1);
  470. end;
  471. function variance(const data : PFloat; Const N : Integer) : float;
  472. begin
  473. If N=1 then
  474. Result:=0
  475. else
  476. Result:=TotalVariance(Data,N)/(N-1);
  477. end;
  478. function totalvariance(const data : array of float) : float;
  479. begin
  480. Result:=TotalVariance(@Data[0],High(Data)+1);
  481. end;
  482. function totalvariance(const data : Pfloat;Const N : Integer) : float;
  483. var S,SS : Float;
  484. begin
  485. If N=1 then
  486. Result:=0
  487. else
  488. begin
  489. SumsAndSquares(Data,N,S,SS);
  490. Result := SS-Sqr(S)/(N-1);
  491. end;
  492. end;
  493. function randg(mean,stddev : float) : float;
  494. Var U1,S2 : Float;
  495. begin
  496. repeat
  497. u1:= 2*random-1;
  498. S2:=Sqr(U1)+sqr(2*random-1);
  499. until s2<1;
  500. randg:=Sqrt(-2*ln(S2)/S2)*u1*stddev+Mean;
  501. end;
  502. function popnstddev(const data : array of float) : float;
  503. begin
  504. PopnStdDev:=Sqrt(PopnVariance(@Data[0],High(Data)+1));
  505. end;
  506. function popnstddev(const data : PFloat; Const N : Integer) : float;
  507. begin
  508. PopnStdDev:=Sqrt(PopnVariance(Data,N));
  509. end;
  510. function popnvariance(const data : array of float) : float;
  511. begin
  512. popnvariance:=popnvariance(@data[0],high(Data)+1);
  513. end;
  514. function popnvariance(const data : PFloat; Const N : Integer) : float;
  515. begin
  516. PopnVariance:=TotalVariance(Data,N)/N;
  517. end;
  518. procedure momentskewkurtosis(const data : array of float;
  519. var m1,m2,m3,m4,skew,kurtosis : float);
  520. begin
  521. momentskewkurtosis(@Data[0],High(Data)+1,m1,m2,m3,m4,skew,kurtosis);
  522. end;
  523. procedure momentskewkurtosis(const data : PFloat; Const N : Integer;
  524. var m1,m2,m3,m4,skew,kurtosis : float);
  525. Var S,SS,SC,SQ,invN,Acc,M1S,S2N,S3N,temp : Float;
  526. I : Longint;
  527. begin
  528. invN:=1.0/N;
  529. s:=0;
  530. ss:=0;
  531. sq:=0;
  532. sc:=0;
  533. for i:=0 to N-1 do
  534. begin
  535. temp:=Data[i]; { faster }
  536. S:=S+temp;
  537. acc:=temp*temp;
  538. ss:=ss+acc;
  539. Acc:=acc*temp;
  540. Sc:=sc+acc;
  541. acc:=acc*temp;
  542. sq:=sq+acc;
  543. end;
  544. M1:=s*invN;
  545. M1S:=M1*M1;
  546. S2N:=SS*invN;
  547. S3N:=SC*invN;
  548. M2:=S2N-M1S;
  549. M3:=S3N-(M1*3*S2N) + 2*M1S*M1;
  550. M4:=SQ*invN - (M1 * 4 * S3N) + (M1S*6*S2N-3*Sqr(M1S));
  551. Skew:=M3*power(M2,-3/2);
  552. Kurtosis:=M4 / Sqr(M2);
  553. end;
  554. function norm(const data : array of float) : float;
  555. begin
  556. norm:=Norm(@data[0],High(Data)+1);
  557. end;
  558. function norm(const data : PFloat; Const N : Integer) : float;
  559. begin
  560. norm:=sqrt(sumofsquares(data,N));
  561. end;
  562. function MinIntValue(const Data: array of Integer): Integer;
  563. var
  564. I: Integer;
  565. begin
  566. Result := Data[Low(Data)];
  567. For I := Succ(Low(Data)) To High(Data) Do
  568. If Data[I] < Result Then Result := Data[I];
  569. end;
  570. function MinValue(const Data: array of Integer): Integer;
  571. begin
  572. Result:=MinValue(Pinteger(@Data[0]),High(Data)+1)
  573. end;
  574. function MinValue(const Data: PInteger; Const N : Integer): Integer;
  575. var
  576. I: Integer;
  577. begin
  578. Result := Data[0];
  579. For I := 0 To N-1 do
  580. If Data[I] < Result Then Result := Data[I];
  581. end;
  582. function minvalue(const data : array of float) : float;
  583. begin
  584. Result:=minvalue(PFloat(@data[0]),High(Data)+1);
  585. end;
  586. function minvalue(const data : PFloat; Const N : Integer) : float;
  587. var
  588. i : longint;
  589. begin
  590. { get an initial value }
  591. minvalue:=data[0];
  592. for i:=0 to N-1 do
  593. if data[i]<minvalue then
  594. minvalue:=data[i];
  595. end;
  596. function MaxIntValue(const Data: array of Integer): Integer;
  597. var
  598. I: Integer;
  599. begin
  600. Result := Data[Low(Data)];
  601. For I := Succ(Low(Data)) To High(Data) Do
  602. If Data[I] > Result Then Result := Data[I];
  603. end;
  604. function maxvalue(const data : array of float) : float;
  605. begin
  606. Result:=maxvalue(PFloat(@data[0]),High(Data)+1);
  607. end;
  608. function maxvalue(const data : PFloat; Const N : Integer) : float;
  609. var
  610. i : longint;
  611. begin
  612. { get an initial value }
  613. maxvalue:=data[0];
  614. for i:=0 to N-1 do
  615. if data[i]>maxvalue then
  616. maxvalue:=data[i];
  617. end;
  618. function MaxValue(const Data: array of Integer): Integer;
  619. begin
  620. Result:=MaxValue(PInteger(@Data[0]),High(Data)+1)
  621. end;
  622. function maxvalue(const data : PInteger; Const N : Integer) : Integer;
  623. var
  624. i : longint;
  625. begin
  626. { get an initial value }
  627. maxvalue:=data[0];
  628. for i:=0 to N-1 do
  629. if data[i]>maxvalue then
  630. maxvalue:=data[i];
  631. end;
  632. function Min(Int1,Int2:Integer):Integer;
  633. begin
  634. If Int1 < Int2 Then Result := Int1
  635. Else Result := Int2;
  636. end;
  637. function Min(Int1,Int2:Cardinal):Cardinal;
  638. begin
  639. If Int1 < Int2 Then Result := Int1
  640. Else Result := Int2;
  641. end;
  642. function Max(Int1,Int2:Integer):Integer;
  643. begin
  644. If Int1 > Int2 Then Result := Int1
  645. Else Result := Int2;
  646. end;
  647. function Max(Int1,Int2:Cardinal):Cardinal;
  648. begin
  649. If Int1 > Int2 Then Result := Int1
  650. Else Result := Int2;
  651. end;
  652. end.
  653. {
  654. $Log$
  655. Revision 1.23 2000-07-08 06:45:07 michael
  656. + Added some functions
  657. Revision 1.22 2000/07/06 21:59:25 michael
  658. + Added many overloaded functions with as argument pointer to
  659. array and count
  660. + Implemented meanandstddev
  661. + Improved power
  662. Revision 1.21 2000/07/06 12:13:59 michael
  663. + SOme changes in error reporting
  664. Revision 1.20 2000/07/05 13:19:59 michael
  665. + Corrected arsinh function
  666. Revision 1.19 2000/07/04 20:53:22 michael
  667. + Exceptions now used for errors
  668. Revision 1.18 2000/04/29 10:10:51 jonas
  669. * fixed arctan2 (tbug788 now works correctly)
  670. Revision 1.17 2000/04/20 13:12:40 pierre
  671. * fix bug visible in new tests/webtbs/tbug788 file
  672. Revision 1.16 2000/04/20 08:14:27 jonas
  673. * better arcsin/arccos from Arjan van Dijk
  674. Revision 1.15 2000/02/09 16:59:32 peter
  675. * truncated log
  676. Revision 1.14 2000/01/11 21:07:33 marco
  677. * Changed some (%ebp) to real parameters
  678. Revision 1.13 2000/01/07 16:41:43 daniel
  679. * copyright 2000
  680. Revision 1.12 1999/09/21 20:47:05 florian
  681. * ceil and floor still had bugs :), hopefully it's the final fix now
  682. }