math.pp 19 KB

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