math.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  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. function stddev(const data : PFloat; Const N : Integer) : float;
  134. { calculates the mean and stddev }
  135. procedure meanandstddev(const data : array of float;
  136. var mean,stddev : float);
  137. procedure meanandstddev(const data : PFloat;
  138. Const N : Longint;var mean,stddev : float);
  139. function variance(const data : array of float) : float;
  140. function totalvariance(const data : array of float) : float;
  141. function variance(const data : PFloat; Const N : Integer) : float;
  142. function totalvariance(const data : PFloat; Const N : Integer) : float;
  143. { returns random values with gaussian distribution }
  144. function randg(mean,stddev : float) : float;
  145. { I don't know what the following functions do: }
  146. function popnstddev(const data : array of float) : float;
  147. function popnstddev(const data : PFloat; Const N : Integer) : float;
  148. function popnvariance(const data : PFloat; Const N : Integer) : float;
  149. function popnvariance(const data : array of float) : float;
  150. procedure momentskewkurtosis(const data : array of float;
  151. var m1,m2,m3,m4,skew,kurtosis : float);
  152. procedure momentskewkurtosis(const data : PFloat; Const N : Integer;
  153. var m1,m2,m3,m4,skew,kurtosis : float);
  154. { geometrical function }
  155. { returns the euclidean L2 norm }
  156. function norm(const data : array of float) : float;
  157. function norm(const data : PFloat; Const N : Integer) : float;
  158. implementation
  159. ResourceString
  160. SMathError = 'Math Error : %s';
  161. SInvalidArgument = 'Invalid argument';
  162. Procedure DoMathError(Const S : String);
  163. begin
  164. Raise EMathError.CreateFmt(SMathError,[S]);
  165. end;
  166. Procedure InvalidArgument;
  167. begin
  168. Raise EInvalidArgument.Create(SInvalidArgument);
  169. end;
  170. function degtorad(deg : float) : float;
  171. begin
  172. degtorad:=deg*(pi/180.0);
  173. end;
  174. function radtodeg(rad : float) : float;
  175. begin
  176. radtodeg:=rad*(180.0/pi);
  177. end;
  178. function gradtorad(grad : float) : float;
  179. begin
  180. gradtorad:=grad*(pi/200.0);
  181. end;
  182. function radtograd(rad : float) : float;
  183. begin
  184. radtograd:=rad*(200.0/pi);
  185. end;
  186. function degtograd(deg : float) : float;
  187. begin
  188. degtograd:=deg*(200.0/180.0);
  189. end;
  190. function gradtodeg(grad : float) : float;
  191. begin
  192. gradtodeg:=grad*(180.0/200.0);
  193. end;
  194. function cycletorad(cycle : float) : float;
  195. begin
  196. cycletorad:=(2*pi)*cycle;
  197. end;
  198. function radtocycle(rad : float) : float;
  199. begin
  200. { avoid division }
  201. radtocycle:=rad*(1/(2*pi));
  202. end;
  203. function tan(x : float) : float;
  204. begin
  205. Tan:=Sin(x)/Cos(x)
  206. end;
  207. function cotan(x : float) : float;
  208. begin
  209. cotan:=Cos(X)/Sin(X);
  210. end;
  211. procedure sincos(theta : float;var sinus,cosinus : float);
  212. begin
  213. {$ifndef i386}
  214. sinus:=sin(theta);
  215. cosinus:=cos(theta);
  216. {$else}
  217. asm
  218. fldl theta
  219. fsincos
  220. fwait
  221. movl cosinus,%eax
  222. fstpl (%eax)
  223. movl sinus,%eax
  224. fstpl (%eax)
  225. end;
  226. {$endif}
  227. end;
  228. { Sign, ArcSin and ArcCos from Arjan van Dijk ([email protected]) }
  229. function sign(x : float) : float;
  230. begin
  231. if x > 0 then sign := 1.0
  232. else if x < 0 then sign := -1.0
  233. else sign := 0.0;
  234. end;
  235. function arcsin(x : float) : float;
  236. begin
  237. if abs(x) > 1 then InvalidArgument
  238. else if abs(x) < 0.5 then
  239. arcsin := arctan(x/sqrt(1-sqr(x)))
  240. else
  241. arcsin := sign(x) * (pi*0.5 - arctan(sqrt(1 / sqr(x) - 1)));
  242. end;
  243. function Arccos(x : Float) : Float;
  244. begin
  245. arccos := pi*0.5 - arcsin(x);
  246. end;
  247. function arctan2( x,y : float) : float;
  248. {$ifndef i386}
  249. begin
  250. ArcTan2:=ArcTan(x/y);
  251. {$else}
  252. { without the assembler keyword, you have to store the result to }
  253. { __result at the end of the assembler block (JM) }
  254. assembler;
  255. asm
  256. fldt X
  257. fldt Y
  258. fpatan
  259. //leave
  260. // ret $20 This is wrong for 4 byte aligned OS !!
  261. {$endif}
  262. end;
  263. function cosh(x : float) : float;
  264. var
  265. temp : float;
  266. begin
  267. temp:=exp(x);
  268. cosh:=0.5*(temp+1.0/temp);
  269. end;
  270. function sinh(x : float) : float;
  271. var
  272. temp : float;
  273. begin
  274. temp:=exp(x);
  275. sinh:=0.5*(temp-1.0/temp);
  276. end;
  277. Const MaxTanh=5000; { rather arbitrary, but more or less correct }
  278. function tanh(x : float) : float;
  279. var Temp : float;
  280. begin
  281. if x>MaxTanh then exit(1.0)
  282. else if x<-MaxTanh then exit (-1.0);
  283. temp:=exp(-2*x);
  284. tanh:=(1-temp)/(1+temp)
  285. end;
  286. function arccosh(x : float) : float;
  287. begin
  288. arccosh:=arcosh(x);
  289. end;
  290. function arcsinh(x : float) : float;
  291. begin
  292. arcsinh:=arsinh(x);
  293. end;
  294. function arctanh(x : float) : float;
  295. begin
  296. if x>1 then InvalidArgument;
  297. arctanh:=artanh(x);
  298. end;
  299. function arcosh(x : float) : float;
  300. begin
  301. if x<1 then InvalidArgument;
  302. arcosh:=Ln(x+Sqrt(x*x-1));
  303. end;
  304. function arsinh(x : float) : float;
  305. begin
  306. arsinh:=Ln(x+Sqrt(1+x*x));
  307. end;
  308. function artanh(x : float) : float;
  309. begin
  310. If abs(x)>1 then InvalidArgument;
  311. artanh:=(Ln((1+x)/(1-x)))*0.5;
  312. end;
  313. function hypot(x,y : float) : float;
  314. begin
  315. hypot:=Sqrt(x*x+y*y)
  316. end;
  317. function log10(x : float) : float;
  318. begin
  319. log10:=ln(x)/ln(10);
  320. end;
  321. function log2(x : float) : float;
  322. begin
  323. log2:=ln(x)/ln(2)
  324. end;
  325. function logn(n,x : float) : float;
  326. begin
  327. if n<0 then InvalidArgument;
  328. logn:=ln(x)/ln(n);
  329. end;
  330. function lnxp1(x : float) : float;
  331. begin
  332. if x<-1 then
  333. InvalidArgument;
  334. lnxp1:=ln(1+x);
  335. end;
  336. function power(base,exponent : float) : float;
  337. begin
  338. If Exponent=0.0 then
  339. Result:=1.0
  340. else
  341. If base>0.0 then
  342. Power:=exp(exponent * ln (base))
  343. else if base=0.0 then
  344. Result:=0.0
  345. else
  346. InvalidArgument
  347. end;
  348. function intpower(base : float;exponent : longint) : float;
  349. var
  350. i : longint;
  351. begin
  352. i:=abs(exponent);
  353. intpower:=1.0;
  354. while i>0 do
  355. begin
  356. while (i and 1)=0 do
  357. begin
  358. i:=i shr 1;
  359. base:=sqr(base);
  360. end;
  361. i:=i-1;
  362. intpower:=intpower*base;
  363. end;
  364. if exponent<0 then
  365. intpower:=1.0/intpower;
  366. end;
  367. function ceil(x : float) : longint;
  368. begin
  369. Ceil:=Trunc(x);
  370. If Frac(x)>0 then
  371. Ceil:=Ceil+1;
  372. end;
  373. function floor(x : float) : longint;
  374. begin
  375. Floor:=Trunc(x);
  376. If Frac(x)<0 then
  377. Floor := Floor-1;
  378. end;
  379. procedure frexp(x : float;var mantissa,exponent : float);
  380. begin
  381. end;
  382. function ldexp(x : float;p : longint) : float;
  383. begin
  384. ldexp:=x*intpower(2.0,p);
  385. end;
  386. function mean(const data : array of float) : float;
  387. begin
  388. Result:=Mean(@data[0],High(Data)+1);
  389. end;
  390. function mean(const data : PFloat; Const N : longint) : float;
  391. begin
  392. mean:=sum(Data,N);
  393. mean:=mean/N;
  394. end;
  395. function sum(const data : array of float) : float;
  396. begin
  397. Result:=Sum(@Data[0],High(Data)+1);
  398. end;
  399. function sum(const data : PFloat;Const N : longint) : float;
  400. var
  401. i : longint;
  402. begin
  403. sum:=0.0;
  404. for i:=0 to N-1 do
  405. sum:=sum+data[i];
  406. end;
  407. function sumofsquares(const data : array of float) : float;
  408. begin
  409. Result:=sumofsquares(@data[0],High(Data)+1);
  410. end;
  411. function sumofsquares(const data : PFloat; Const N : Integer) : float;
  412. var
  413. i : longint;
  414. begin
  415. sumofsquares:=0.0;
  416. for i:=0 to N-1 do
  417. sumofsquares:=sumofsquares+sqr(data[i]);
  418. end;
  419. procedure sumsandsquares(const data : array of float;
  420. var sum,sumofsquares : float);
  421. begin
  422. sumsandsquares (@Data[0],High(Data)+1,Sum,sumofsquares);
  423. end;
  424. procedure sumsandsquares(const data : PFloat; Const N : Integer;
  425. var sum,sumofsquares : float);
  426. var
  427. i : Integer;
  428. temp : float;
  429. begin
  430. sumofsquares:=0.0;
  431. sum:=0.0;
  432. for i:=0 to N-1 do
  433. begin
  434. temp:=data[i];
  435. sumofsquares:=sumofsquares+sqr(temp);
  436. sum:=sum+temp;
  437. end;
  438. end;
  439. function stddev(const data : array of float) : float;
  440. begin
  441. Result:=Stddev(@Data[0],High(Data)+1)
  442. end;
  443. function stddev(const data : PFloat; Const N : Integer) : float;
  444. begin
  445. StdDev:=Sqrt(Variance(Data,N));
  446. end;
  447. procedure meanandstddev(const data : array of float;
  448. var mean,stddev : float);
  449. begin
  450. Meanandstddev(@Data[0],High(Data)+1,Mean,stddev);
  451. end;
  452. procedure meanandstddev(const data : PFloat;
  453. Const N : Longint;var mean,stddev : float);
  454. Var I : longint;
  455. begin
  456. Mean:=0;
  457. StdDev:=0;
  458. For I:=0 to N-1 do
  459. begin
  460. Mean:=Mean+Data[i];
  461. StdDev:=StdDev+Sqr(Data[i]);
  462. end;
  463. Mean:=Mean/N;
  464. StdDev:=(StdDev-N*Sqr(Mean));
  465. If N>1 then
  466. StdDev:=Sqrt(Stddev/(N-1))
  467. else
  468. StdDev:=0;
  469. end;
  470. function variance(const data : array of float) : float;
  471. begin
  472. Variance:=Variance(@Data[0],High(Data)+1);
  473. end;
  474. function variance(const data : PFloat; Const N : Integer) : float;
  475. begin
  476. If N=1 then
  477. Result:=0
  478. else
  479. Result:=TotalVariance(Data,N)/(N-1);
  480. end;
  481. function totalvariance(const data : array of float) : float;
  482. begin
  483. Result:=TotalVariance(@Data[0],High(Data)+1);
  484. end;
  485. function totalvariance(const data : Pfloat;Const N : Integer) : float;
  486. var S,SS : Float;
  487. begin
  488. If N=1 then
  489. Result:=0
  490. else
  491. begin
  492. SumsAndSquares(Data,N,S,SS);
  493. Result := SS-Sqr(S)/N;
  494. end;
  495. end;
  496. function randg(mean,stddev : float) : float;
  497. Var U1,S2 : Float;
  498. begin
  499. repeat
  500. u1:= 2*random-1;
  501. S2:=Sqr(U1)+sqr(2*random-1);
  502. until s2<1;
  503. randg:=Sqrt(-2*ln(S2)/S2)*u1*stddev+Mean;
  504. end;
  505. function popnstddev(const data : array of float) : float;
  506. begin
  507. PopnStdDev:=Sqrt(PopnVariance(@Data[0],High(Data)+1));
  508. end;
  509. function popnstddev(const data : PFloat; Const N : Integer) : float;
  510. begin
  511. PopnStdDev:=Sqrt(PopnVariance(Data,N));
  512. end;
  513. function popnvariance(const data : array of float) : float;
  514. begin
  515. popnvariance:=popnvariance(@data[0],high(Data)+1);
  516. end;
  517. function popnvariance(const data : PFloat; Const N : Integer) : float;
  518. begin
  519. PopnVariance:=TotalVariance(Data,N)/N;
  520. end;
  521. procedure momentskewkurtosis(const data : array of float;
  522. var m1,m2,m3,m4,skew,kurtosis : float);
  523. begin
  524. momentskewkurtosis(@Data[0],High(Data)+1,m1,m2,m3,m4,skew,kurtosis);
  525. end;
  526. procedure momentskewkurtosis(const data : PFloat; Const N : Integer;
  527. var m1,m2,m3,m4,skew,kurtosis : float);
  528. Var S,SS,SC,SQ,invN,Acc,M1S,S2N,S3N,temp : Float;
  529. I : Longint;
  530. begin
  531. invN:=1.0/N;
  532. s:=0;
  533. ss:=0;
  534. sq:=0;
  535. sc:=0;
  536. for i:=0 to N-1 do
  537. begin
  538. temp:=Data[i]; { faster }
  539. S:=S+temp;
  540. acc:=temp*temp;
  541. ss:=ss+acc;
  542. Acc:=acc*temp;
  543. Sc:=sc+acc;
  544. acc:=acc*temp;
  545. sq:=sq+acc;
  546. end;
  547. M1:=s*invN;
  548. M1S:=M1*M1;
  549. S2N:=SS*invN;
  550. S3N:=SC*invN;
  551. M2:=S2N-M1S;
  552. M3:=S3N-(M1*3*S2N) + 2*M1S*M1;
  553. M4:=SQ*invN - (M1 * 4 * S3N) + (M1S*6*S2N-3*Sqr(M1S));
  554. Skew:=M3*power(M2,-3/2);
  555. Kurtosis:=M4 / Sqr(M2);
  556. end;
  557. function norm(const data : array of float) : float;
  558. begin
  559. norm:=Norm(@data[0],High(Data)+1);
  560. end;
  561. function norm(const data : PFloat; Const N : Integer) : float;
  562. begin
  563. norm:=sqrt(sumofsquares(data,N));
  564. end;
  565. function MinIntValue(const Data: array of Integer): Integer;
  566. var
  567. I: Integer;
  568. begin
  569. Result := Data[Low(Data)];
  570. For I := Succ(Low(Data)) To High(Data) Do
  571. If Data[I] < Result Then Result := Data[I];
  572. end;
  573. function MinValue(const Data: array of Integer): Integer;
  574. begin
  575. Result:=MinValue(Pinteger(@Data[0]),High(Data)+1)
  576. end;
  577. function MinValue(const Data: PInteger; Const N : Integer): Integer;
  578. var
  579. I: Integer;
  580. begin
  581. Result := Data[0];
  582. For I := 0 To N-1 do
  583. If Data[I] < Result Then Result := Data[I];
  584. end;
  585. function minvalue(const data : array of float) : float;
  586. begin
  587. Result:=minvalue(PFloat(@data[0]),High(Data)+1);
  588. end;
  589. function minvalue(const data : PFloat; Const N : Integer) : float;
  590. var
  591. i : longint;
  592. begin
  593. { get an initial value }
  594. minvalue:=data[0];
  595. for i:=0 to N-1 do
  596. if data[i]<minvalue then
  597. minvalue:=data[i];
  598. end;
  599. function MaxIntValue(const Data: array of Integer): Integer;
  600. var
  601. I: Integer;
  602. begin
  603. Result := Data[Low(Data)];
  604. For I := Succ(Low(Data)) To High(Data) Do
  605. If Data[I] > Result Then Result := Data[I];
  606. end;
  607. function maxvalue(const data : array of float) : float;
  608. begin
  609. Result:=maxvalue(PFloat(@data[0]),High(Data)+1);
  610. end;
  611. function maxvalue(const data : PFloat; Const N : Integer) : float;
  612. var
  613. i : longint;
  614. begin
  615. { get an initial value }
  616. maxvalue:=data[0];
  617. for i:=0 to N-1 do
  618. if data[i]>maxvalue then
  619. maxvalue:=data[i];
  620. end;
  621. function MaxValue(const Data: array of Integer): Integer;
  622. begin
  623. Result:=MaxValue(PInteger(@Data[0]),High(Data)+1)
  624. end;
  625. function maxvalue(const data : PInteger; Const N : Integer) : Integer;
  626. var
  627. i : longint;
  628. begin
  629. { get an initial value }
  630. maxvalue:=data[0];
  631. for i:=0 to N-1 do
  632. if data[i]>maxvalue then
  633. maxvalue:=data[i];
  634. end;
  635. function Min(Int1,Int2:Integer):Integer;
  636. begin
  637. If Int1 < Int2 Then Result := Int1
  638. Else Result := Int2;
  639. end;
  640. function Min(Int1,Int2:Cardinal):Cardinal;
  641. begin
  642. If Int1 < Int2 Then Result := Int1
  643. Else Result := Int2;
  644. end;
  645. function Max(Int1,Int2:Integer):Integer;
  646. begin
  647. If Int1 > Int2 Then Result := Int1
  648. Else Result := Int2;
  649. end;
  650. function Max(Int1,Int2:Cardinal):Cardinal;
  651. begin
  652. If Int1 > Int2 Then Result := Int1
  653. Else Result := Int2;
  654. end;
  655. end.
  656. {
  657. $Log$
  658. Revision 1.25 2000-07-08 17:12:56 michael
  659. + Final fixes
  660. Revision 1.24 2000/07/08 07:03:20 michael
  661. + fixed meanandstddev
  662. Revision 1.23 2000/07/08 06:45:07 michael
  663. + Added some functions
  664. Revision 1.22 2000/07/06 21:59:25 michael
  665. + Added many overloaded functions with as argument pointer to
  666. array and count
  667. + Implemented meanandstddev
  668. + Improved power
  669. Revision 1.21 2000/07/06 12:13:59 michael
  670. + SOme changes in error reporting
  671. Revision 1.20 2000/07/05 13:19:59 michael
  672. + Corrected arsinh function
  673. Revision 1.19 2000/07/04 20:53:22 michael
  674. + Exceptions now used for errors
  675. Revision 1.18 2000/04/29 10:10:51 jonas
  676. * fixed arctan2 (tbug788 now works correctly)
  677. Revision 1.17 2000/04/20 13:12:40 pierre
  678. * fix bug visible in new tests/webtbs/tbug788 file
  679. Revision 1.16 2000/04/20 08:14:27 jonas
  680. * better arcsin/arccos from Arjan van Dijk
  681. Revision 1.15 2000/02/09 16:59:32 peter
  682. * truncated log
  683. Revision 1.14 2000/01/11 21:07:33 marco
  684. * Changed some (%ebp) to real parameters
  685. Revision 1.13 2000/01/07 16:41:43 daniel
  686. * copyright 2000
  687. Revision 1.12 1999/09/21 20:47:05 florian
  688. * ceil and floor still had bugs :), hopefully it's the final fix now
  689. }