math.tex 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 2000 by Florian Klaempfl
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. \chapter{The MATH unit}
  22. \FPCexampledir{mathex}
  23. This chapter describes the \file{math} unit. The \var{math} unit
  24. was initially written by Florian Kl\"ampfl. It provides mathematical
  25. functions which aren't covered by the system unit.
  26. This chapter starts out with a definition of all types and constants
  27. that are defined, after which an overview is presented of the available
  28. functions, grouped by category, and the last part contains a
  29. complete explanation of each function.
  30. The following things must be taken into account when using this unit:
  31. \begin{enumerate}
  32. \item This unit is compiled in Object Pascal mode so all
  33. \var{integers} are 32 bit.
  34. \item Some overloaded functions exist for data arrays of integers and
  35. floats. When using the address operator (\var{@}) to pass an array of
  36. data to such a function, make sure the address is typecasted to the
  37. right type, or turn on the 'typed address operator' feature. failing to
  38. do so, will cause the compiler not be able to decide which function you
  39. want to call.
  40. \end{enumerate}
  41. \section{Constants and types}
  42. The following types are defined in the \file{math} unit:
  43. \begin{verbatim}
  44. Type
  45. Float = Extended;
  46. PFloat = ^FLoat
  47. \end{verbatim}
  48. All calculations are done with the Float type. This allows to
  49. recompile the unit with a different float type to obtain a
  50. desired precision. The pointer type is used in functions that accept
  51. an array of values of arbitrary length.
  52. \begin{verbatim}
  53. Type
  54. TPaymentTime = (PTEndOfPeriod,PTStartOfPeriod);
  55. \end{verbatim}
  56. \var{TPaymentTime} is used in the financial calculations.
  57. \begin{verbatim}
  58. Type
  59. EInvalidArgument = Class(EMathError);
  60. \end{verbatim}
  61. The \var{EInvalidArgument} exception is used to report invalid arguments.
  62. \section{Function list by category}
  63. What follows is a listing of the available functions, grouped by category.
  64. For each function there is a reference to the page where you can find the
  65. function.
  66. \subsection{Min/max determination}
  67. Functions to determine the minimum or maximum of numbers:
  68. \begin{funclist}
  69. \funcref{max}{Maximum of 2 values}
  70. \funcref{maxIntValue}{Maximum of an array of integer values}
  71. \funcref{maxvalue}{Maximum of an array of values}
  72. \funcref{min}{Minimum of 2 values}
  73. \funcref{minIntValue}{Minimum of an array of integer values}
  74. \funcref{minvalue}{Minimum of an array of values}
  75. \end{funclist}
  76. \subsection{Angle conversion}
  77. \begin{funclist}
  78. \funcref{cycletorad}{convert cycles to radians}
  79. \funcref{degtograd}{convert degrees to grads}
  80. \funcref{degtorad}{convert degrees to radians}
  81. \funcref{gradtodeg}{convert grads to degrees}
  82. \funcref{gradtorad}{convert grads to radians}
  83. \funcref{radtocycle}{convert radians to cycles}
  84. \funcref{radtodeg}{convert radians to degrees}
  85. \funcref{radtograd}{convert radians to grads}
  86. \end{funclist}
  87. \subsection{Trigoniometric functions}
  88. \begin{funclist}
  89. \funcref{arccos}{calculate reverse cosine}
  90. \funcref{arcsin}{calculate reverse sine}
  91. \funcref{arctan2}{calculate reverse tangent}
  92. \funcref{cotan}{calculate cotangent}
  93. \procref{sincos}{calculate sine and cosine}
  94. \funcref{tan}{calculate tangent}
  95. \end{funclist}
  96. \subsection{Hyperbolic functions}
  97. \begin{funclist}
  98. \funcref{arcosh}{caculate reverse hyperbolic cosine}
  99. \funcref{arsinh}{caculate reverse hyperbolic sine}
  100. \funcref{artanh}{caculate reverse hyperbolic tangent}
  101. \funcref{cosh}{calculate hyperbolic cosine}
  102. \funcref{sinh}{calculate hyperbolic sine}
  103. \funcref{tanh}{calculate hyperbolic tangent}
  104. \end{funclist}
  105. \subsection{Exponential and logarithmic functions}
  106. \begin{funclist}
  107. \funcref{intpower}{Raise float to integer power}
  108. \funcref{ldexp}{Calculate $2^p x$}
  109. \funcref{lnxp1}{calculate \var{log(x+1)}}
  110. \funcref{log10}{calculate 10-base log}
  111. \funcref{log2}{calculate 2-base log}
  112. \funcref{logn}{calculate N-base log}
  113. \funcref{power}{raise float to arbitrary power}
  114. \end{funclist}
  115. \subsection{Number converting}
  116. \begin{funclist}
  117. \funcref{ceil}{Round to infinity}
  118. \funcref{floor}{Round to minus infinity}
  119. \procref{frexp}{Return mantissa and exponent}
  120. \end{funclist}
  121. \subsection{Statistical functions}
  122. \begin{funclist}
  123. \funcref{mean}{Mean of values}
  124. \procref{meanandstddev}{Mean and standard deviation of values}
  125. \procref{momentskewkurtosis}{Moments, skew and kurtosis}
  126. \funcref{popnstddev}{Population standarddeviation }
  127. \funcref{popnvariance}{Population variance}
  128. \funcref{randg}{Gaussian distributed randum value}
  129. \funcref{stddev}{Standard deviation}
  130. \funcref{sum}{Sum of values}
  131. \funcref{sumofsquares}{Sum of squared values}
  132. \procref{sumsandsquares}{Sum of values and squared values}
  133. \funcref{totalvariance}{Total variance of values}
  134. \funcref{variance}{variance of values}
  135. \end{funclist}
  136. \subsection{Geometrical functions}
  137. \begin{funclist}
  138. \funcref{hypot}{Hypotenuse of triangle}
  139. \funcref{norm}{Euclidian norm}
  140. \end{funclist}
  141. \section{Functions and Procedures}
  142. \begin{function}{arccos}
  143. \Declaration
  144. Function arccos(x : float) : float;
  145. \Description
  146. \var{Arccos} returns the inverse cosine of its argument \var{x}. The
  147. argument \var{x} should lie between -1 and 1 (borders included).
  148. \Errors
  149. If the argument \var{x} is not in the allowed range, an
  150. \var{EInvalidArgument} exception is raised.
  151. \SeeAlso
  152. \seef{arcsin}, \seef{arcosh}, \seef{arsinh}, \seef{artanh}
  153. \end{function}
  154. \FPCexample{ex1}
  155. \begin{function}{arcosh}
  156. \Declaration
  157. Function arcosh(x : float) : float;
  158. Function arccosh(x : float) : float;
  159. \Description
  160. \var{Arcosh} returns the inverse hyperbolic cosine of its argument \var{x}.
  161. The argument \var{x} should be larger than 1.
  162. The \var{arccosh} variant of this function is supplied for \delphi
  163. compatibility.
  164. \Errors
  165. If the argument \var{x} is not in the allowed range, an \var{EInvalidArgument}
  166. exception is raised.
  167. \SeeAlso
  168. \seef{cosh}, \seef{sinh}, \seef{arcsin}, \seef{arsinh}, \seef{artanh},
  169. \seef{tanh}
  170. \end{function}
  171. \FPCexample{ex3}
  172. \begin{function}{arcsin}
  173. \Declaration
  174. Function arcsin(x : float) : float;
  175. \Description
  176. \var{Arcsin} returns the inverse sine of its argument \var{x}. The
  177. argument \var{x} should lie between -1 and 1.
  178. \Errors
  179. If the argument \var{x} is not in the allowed range, an \var{EInvalidArgument}
  180. exception is raised.
  181. \SeeAlso
  182. \seef{arccos}, \seef{arcosh}, \seef{arsinh}, \seef{artanh}
  183. \end{function}
  184. \FPCexample{ex2}
  185. \begin{function}{arctan2}
  186. \Declaration
  187. Function arctan2(x,y : float) : float;
  188. \Description
  189. \var{arctan2} calculates \var{arctan(y/x)}, and returns an angle in the
  190. correct quadrant. The returned angle will be in the range $-\pi$ to
  191. $\pi$ radians.
  192. The values of \var{x} and \var{y} must be between -2\^{}64 and 2\^{}64,
  193. moreover \var{x} should be different from zero.
  194. On Intel systems this function is implemented with the native intel
  195. \var{fpatan} instruction.
  196. \Errors
  197. If \var{x} is zero, an overflow error will occur.
  198. \SeeAlso
  199. \seef{arccos}, \seef{arcosh}, \seef{arsinh}, \seef{artanh}
  200. \end{function}
  201. \FPCexample{ex6}
  202. \begin{function}{arsinh}
  203. \Declaration
  204. Function arsinh(x : float) : float;
  205. Function arcsinh(x : float) : float;
  206. \Description
  207. \var{arsinh} returns the inverse hyperbolic sine of its argument \var{x}.
  208. The \var{arscsinh} variant of this function is supplied for \delphi
  209. compatibility.
  210. \Errors
  211. None.
  212. \SeeAlso
  213. \seef{arcosh}, \seef{arccos}, \seef{arcsin}, \seef{artanh}
  214. \end{function}
  215. \FPCexample{ex4}
  216. \begin{function}{artanh}
  217. \Declaration
  218. Function artanh(x : float) : float;
  219. Function arctanh(x : float) : float;
  220. \Description
  221. \var{artanh} returns the inverse hyperbolic tangent of its argument \var{x},
  222. where \var{x} should lie in the interval [-1,1], borders included.
  223. The \var{arctanh} variant of this function is supplied for \delphi compatibility.
  224. \Errors
  225. In case \var{x} is not in the interval [-1,1], an \var{EInvalidArgument}
  226. exception is raised.
  227. \SeeAlso
  228. \seef{arcosh}, \seef{arccos}, \seef{arcsin}, \seef{artanh}
  229. \Errors
  230. \SeeAlso
  231. \end{function}
  232. \FPCexample{ex5}
  233. \begin{function}{ceil}
  234. \Declaration
  235. Function ceil(x : float) : longint;
  236. \Description
  237. \var{Ceil} returns the lowest integer number greater than or equal to \var{x}.
  238. The absolute value of \var{x} should be less than \var{maxint}.
  239. \Errors
  240. If the asolute value of \var{x} is larger than maxint, an overflow error will
  241. occur.
  242. \SeeAlso
  243. \seef{floor}
  244. \end{function}
  245. \FPCexample{ex7}
  246. \begin{function}{cosh}
  247. \Declaration
  248. Function cosh(x : float) : float;
  249. \Description
  250. \var{Cosh} returns the hyperbolic cosine of it's argument {x}.
  251. \Errors
  252. None.
  253. \SeeAlso
  254. \seef{arcosh}, \seef{sinh}, \seef{arsinh}
  255. \end{function}
  256. \FPCexample{ex8}
  257. \begin{function}{cotan}
  258. \Declaration
  259. Function cotan(x : float) : float;
  260. \Description
  261. \var{Cotan} returns the cotangent of it's argument \var{x}. \var{x} should
  262. be different from zero.
  263. \Errors
  264. If \var{x} is zero then a overflow error will occur.
  265. \SeeAlso
  266. \seef{tanh}
  267. \end{function}
  268. \FPCexample{ex9}
  269. \begin{function}{cycletorad}
  270. \Declaration
  271. Function cycletorad(cycle : float) : float;
  272. \Description
  273. \var{Cycletorad} transforms it's argument \var{cycle}
  274. (an angle expressed in cycles) to radians.
  275. (1 cycle is $2 \pi$ radians).
  276. \Errors
  277. None.
  278. \SeeAlso
  279. \seef{degtograd}, \seef{degtorad}, \seef{radtodeg},
  280. \seef{radtograd}, \seef{radtocycle}
  281. \end{function}
  282. \FPCexample{ex10}
  283. \begin{function}{degtograd}
  284. \Declaration
  285. Function degtograd(deg : float) : float;
  286. \Description
  287. \var{Degtograd} transforms it's argument \var{deg} (an angle in degrees)
  288. to grads.
  289. (90 degrees is 100 grad.)
  290. \Errors
  291. None.
  292. \SeeAlso
  293. \seef{cycletorad}, \seef{degtorad}, \seef{radtodeg},
  294. \seef{radtograd}, \seef{radtocycle}
  295. \end{function}
  296. \FPCexample{ex11}
  297. \begin{function}{degtorad}
  298. \Declaration
  299. Function degtorad(deg : float) : float;
  300. \Description
  301. \var{Degtorad} converts it's argument \var{deg} (an angle in degrees) to
  302. radians.
  303. (pi radians is 180 degrees)
  304. \Errors
  305. None.
  306. \SeeAlso
  307. \seef{cycletorad}, \seef{degtograd}, \seef{radtodeg},
  308. \seef{radtograd}, \seef{radtocycle}
  309. \end{function}
  310. \FPCexample{ex12}
  311. \begin{function}{floor}
  312. \Declaration
  313. Function floor(x : float) : longint;
  314. \Description
  315. \var{Floor} returns the largest integer smaller than or equal to \var{x}.
  316. The absolute value of \var{x} should be less than \var{maxint}.
  317. \Errors
  318. If \var{x} is larger than \var{maxint}, an overflow will occur.
  319. \SeeAlso
  320. \seef{ceil}
  321. \end{function}
  322. \FPCexample{ex13}
  323. \begin{procedure}{frexp}
  324. \Declaration
  325. Procedure frexp(x : float;var mantissa : float; var exponent : integer);
  326. \Description
  327. \var{Frexp} returns the mantissa and exponent of it's argument
  328. \var{x} in \var{mantissa} and \var{exponent}.
  329. \Errors
  330. None
  331. \SeeAlso
  332. \end{procedure}
  333. \FPCexample{ex14}
  334. \begin{function}{gradtodeg}
  335. \Declaration
  336. Function gradtodeg(grad : float) : float;
  337. \Description
  338. \var{Gradtodeg} converts its argument \var{grad} (an angle in grads)
  339. to degrees.
  340. (100 grad is 90 degrees)
  341. \Errors
  342. None.
  343. \SeeAlso
  344. \seef{cycletorad}, \seef{degtograd}, \seef{radtodeg},
  345. \seef{radtograd}, \seef{radtocycle}, \seef{gradtorad}
  346. \end{function}
  347. \FPCexample{ex15}
  348. \begin{function}{gradtorad}
  349. \Declaration
  350. Function gradtorad(grad : float) : float;
  351. \Description
  352. \var{Gradtorad} converts its argument \var{grad} (an angle in grads)
  353. to radians.
  354. (200 grad is pi degrees).
  355. \Errors
  356. None.
  357. \SeeAlso
  358. \seef{cycletorad}, \seef{degtograd}, \seef{radtodeg},
  359. \seef{radtograd}, \seef{radtocycle}, \seef{gradtodeg}
  360. \end{function}
  361. \FPCexample{ex16}
  362. \begin{function}{hypot}
  363. \Declaration
  364. Function hypot(x,y : float) : float;
  365. \Description
  366. \var{Hypot} returns the hypotenuse of the triangle where the sides
  367. adjacent to the square angle have lengths \var{x} and \var{y}.
  368. The function uses Pythagoras' rule for this.
  369. \Errors
  370. None.
  371. \SeeAlso
  372. \end{function}
  373. \FPCexample{ex17}
  374. \begin{function}{intpower}
  375. \Declaration
  376. Function intpower(base : float;exponent : longint) : float;
  377. \Description
  378. \var{Intpower} returns \var{base} to the power \var{exponent},
  379. where exponent is an integer value.
  380. \Errors
  381. If \var{base} is zero and the exponent is negative, then an
  382. overflow error will occur.
  383. \SeeAlso
  384. \seef{power}
  385. \end{function}
  386. \FPCexample{ex18}
  387. \begin{function}{ldexp}
  388. \Declaration
  389. Function ldexp(x : float;p : longint) : float;
  390. \Description
  391. \var{Ldexp} returns $2^p x$.
  392. \Errors
  393. None.
  394. \SeeAlso
  395. \seef{lnxp1}, \seef{log10},\seef{log2},\seef{logn}
  396. \end{function}
  397. \FPCexample{ex19}
  398. \begin{function}{lnxp1}
  399. \Declaration
  400. Function lnxp1(x : float) : float;
  401. \Description
  402. \var{Lnxp1} returns the natural logarithm of \var{1+X}. The result
  403. is more precise for small values of \var{x}. \var{x} should be larger
  404. than -1.
  405. \Errors
  406. If $x\leq -1$ then an \var{EInvalidArgument} exception will be raised.
  407. \SeeAlso
  408. \seef{ldexp}, \seef{log10},\seef{log2},\seef{logn}
  409. \end{function}
  410. \FPCexample{ex20}
  411. \begin{function}{log10}
  412. \Declaration
  413. Function log10(x : float) : float;
  414. \Description
  415. \var{Log10} returns the 10-base logarithm of \var{X}.
  416. \Errors
  417. If \var{x} is less than or equal to 0 an 'invalid fpu operation' error
  418. will occur.
  419. \SeeAlso
  420. \seef{ldexp}, \seef{lnxp1},\seef{log2},\seef{logn}
  421. \end{function}
  422. \FPCexample{ex21}
  423. \begin{function}{log2}
  424. \Declaration
  425. Function log2(x : float) : float;
  426. \Description
  427. \var{Log2} returns the 2-base logarithm of \var{X}.
  428. \Errors
  429. If \var{x} is less than or equal to 0 an 'invalid fpu operation' error
  430. will occur.
  431. \SeeAlso
  432. \seef{ldexp}, \seef{lnxp1},\seef{log10},\seef{logn}
  433. \end{function}
  434. \FPCexample{ex22}
  435. \begin{function}{logn}
  436. \Declaration
  437. Function logn(n,x : float) : float;
  438. \Description
  439. \var{Logn} returns the n-base logarithm of \var{X}.
  440. \Errors
  441. If \var{x} is less than or equal to 0 an 'invalid fpu operation' error
  442. will occur.
  443. \SeeAlso
  444. \seef{ldexp}, \seef{lnxp1},\seef{log10},\seef{log2}
  445. \end{function}
  446. \FPCexample{ex23}
  447. \begin{function}{max}
  448. \Declaration
  449. Function max(Int1,Int2:Cardinal):Cardinal;
  450. Function max(Int1,Int2:Integer):Integer;
  451. \Description
  452. \var{Max} returns the maximum of \var{Int1} and \var{Int2}.
  453. \Errors
  454. None.
  455. \SeeAlso
  456. \seef{min}, \seef{maxIntValue}, \seef{maxvalue}
  457. \end{function}
  458. \FPCexample{ex24}
  459. \begin{function}{maxIntValue}
  460. \Declaration
  461. function MaxIntValue(const Data: array of Integer): Integer;
  462. \Description
  463. \var{MaxIntValue} returns the largest integer out of the \var{Data}
  464. array.
  465. This function is provided for \delphi compatibility, use the \seef{maxvalue}
  466. function instead.
  467. \Errors
  468. None.
  469. \SeeAlso
  470. \seef{maxvalue}, \seef{minvalue}, \seef{minIntValue}
  471. \end{function}
  472. \FPCexample{ex25}
  473. \begin{function}{maxvalue}
  474. \Declaration
  475. Function maxvalue(const data : array of float) : float;
  476. Function maxvalue(const data : array of Integer) : Integer;
  477. Function maxvalue(const data : PFloat; Const N : Integer) : float;
  478. Function maxvalue(const data : PInteger; Const N : Integer) : Integer;
  479. \Description
  480. \var{Maxvalue} returns the largest value in the \var{data}
  481. array with integer or float values. The return value has
  482. the same type as the elements of the array.
  483. The third and fourth forms accept a pointer to an array of \var{N}
  484. integer or float values.
  485. \Errors
  486. None.
  487. \SeeAlso
  488. \seef{maxIntValue}, \seef{minvalue}, \seef{minIntValue}
  489. \end{function}
  490. \FPCexample{ex26}
  491. \begin{function}{mean}
  492. \Declaration
  493. Function mean(const data : array of float) : float;
  494. Function mean(const data : PFloat; Const N : longint) : float;
  495. \Description
  496. \var{Mean} returns the average value of \var{data}.
  497. The second form accepts a pointer to an array of \var{N} values.
  498. \Errors
  499. None.
  500. \SeeAlso
  501. \seep{meanandstddev}, \seep{momentskewkurtosis}, \seef{sum}
  502. \end{function}
  503. \FPCexample{ex27}
  504. \begin{procedure}{meanandstddev}
  505. \Declaration
  506. Procedure meanandstddev(const data : array of float;
  507. var mean,stddev : float);
  508. procedure meanandstddev(const data : PFloat;
  509. Const N : Longint;var mean,stddev : float);
  510. \Description
  511. \var{meanandstddev} calculates the mean and standard deviation of \var{data}
  512. and returns the result in \var{mean} and \var{stddev}, respectively.
  513. Stddev is zero if there is only one value.
  514. The second form accepts a pointer to an array of \var{N} values.
  515. \Errors
  516. None.
  517. \SeeAlso
  518. \seef{mean},\seef{sum}, \seef{sumofsquares}, \seep{momentskewkurtosis}
  519. \end{procedure}
  520. \FPCexample{ex28}
  521. \begin{function}{min}
  522. \Declaration
  523. Function min(Int1,Int2:Cardinal):Cardinal;
  524. Function min(Int1,Int2:Integer):Integer;
  525. \Description
  526. \var{min} returns the smallest value of \var{Int1} and \var{Int2};
  527. \Errors
  528. None.
  529. \SeeAlso
  530. \seef{max}
  531. \end{function}
  532. \FPCexample{ex29}
  533. \begin{function}{minIntValue}
  534. \Declaration
  535. Function minIntValue(const Data: array of Integer): Integer;
  536. \Description
  537. \var{MinIntvalue} returns the smallest value in the \var{Data} array.
  538. This function is provided for \delphi compatibility, use \var{minvalue}
  539. instead.
  540. \Errors
  541. None
  542. \SeeAlso
  543. \seef{minvalue}, \seef{maxIntValue}, \seef{maxvalue}
  544. \end{function}
  545. \FPCexample{ex30}
  546. \begin{function}{minvalue}
  547. \Declaration
  548. Function minvalue(const data : array of float) : float;
  549. Function minvalue(const data : array of Integer) : Integer;
  550. Function minvalue(const data : PFloat; Const N : Integer) : float;
  551. Function minvalue(const data : PInteger; Const N : Integer) : Integer;
  552. \Description
  553. \var{Minvalue} returns the smallest value in the \var{data}
  554. array with integer or float values. The return value has
  555. the same type as the elements of the array.
  556. The third and fourth forms accept a pointer to an array of \var{N}
  557. integer or float values.
  558. \Errors
  559. None.
  560. \SeeAlso
  561. \seef{maxIntValue}, \seef{maxvalue}, \seef{minIntValue}
  562. \end{function}
  563. \FPCexample{ex31}
  564. \begin{procedure}{momentskewkurtosis}
  565. \Declaration
  566. procedure momentskewkurtosis(const data : array of float;
  567. var m1,m2,m3,m4,skew,kurtosis : float);
  568. procedure momentskewkurtosis(const data : PFloat; Const N : Integer;
  569. var m1,m2,m3,m4,skew,kurtosis : float);
  570. \Description
  571. \var{momentskewkurtosis} calculates the 4 first moments of the distribution
  572. of valuesin \var{data} and returns them in \var{m1},\var{m2},\var{m3} and
  573. \var{m4}, as well as the \var{skew} and \var{kurtosis}.
  574. \Errors
  575. None.
  576. \SeeAlso
  577. \seef{mean}, \seep{meanandstddev}
  578. \end{procedure}
  579. \FPCexample{ex32}
  580. \begin{function}{norm}
  581. \Declaration
  582. Function norm(const data : array of float) : float;
  583. Function norm(const data : PFloat; Const N : Integer) : float;
  584. \Description
  585. \var{Norm} calculates the Euclidian norm of the array of data.
  586. This equals \var{sqrt(sumofsquares(data))}.
  587. The second form accepts a pointer to an array of \var{N} values.
  588. \Errors
  589. None.
  590. \SeeAlso
  591. \seef{sumofsquares}
  592. \end{function}
  593. \FPCexample{ex33}
  594. \begin{function}{popnstddev}
  595. \Declaration
  596. Function popnstddev(const data : array of float) : float;
  597. Function popnstddev(const data : PFloat; Const N : Integer) : float;
  598. \Description
  599. \var{Popnstddev} returns the square root of the population variance of
  600. the values in the \var{Data} array. It returns zero if there is only one value.
  601. The second form of this function accepts a pointer to an array of \var{N}
  602. values.
  603. \Errors
  604. None.
  605. \SeeAlso
  606. \seef{popnvariance}, \seef{mean}, \seep{meanandstddev}, \seef{stddev},
  607. \seep{momentskewkurtosis}
  608. \end{function}
  609. \FPCexample{ex35}
  610. \begin{function}{popnvariance}
  611. \Declaration
  612. Function popnvariance(const data : array of float) : float;
  613. Function popnvariance(const data : PFloat; Const N : Integer) : float;
  614. \Description
  615. \var{Popnvariance} returns the square root of the population variance of
  616. the values in the \var{Data} array. It returns zero if there is only one value.
  617. The second form of this function accepts a pointer to an array of \var{N}
  618. values.
  619. \Errors
  620. None.
  621. \SeeAlso
  622. \seef{popnstddev}, \seef{mean}, \seep{meanandstddev}, \seef{stddev},
  623. \seep{momentskewkurtosis}
  624. \end{function}
  625. \FPCexample{ex36}
  626. \begin{function}{power}
  627. \Declaration
  628. Function power(base,exponent : float) : float;
  629. \Description
  630. \var{power} raises \var{base} to the power \var{power}. This is equivalent
  631. to \var{exp(power*ln(base))}. Therefore \var{base} should be non-negative.
  632. \Errors
  633. None.
  634. \SeeAlso
  635. \seef{intpower}
  636. \end{function}
  637. \FPCexample{ex34}
  638. \begin{function}{radtocycle}
  639. \Declaration
  640. Function radtocycle(rad : float) : float;
  641. \Description
  642. \var{Radtocycle} converts its argument \var{rad} (an angle expressed in
  643. radians) to an angle in cycles.
  644. (1 cycle equals 2 pi radians)
  645. \Errors
  646. None.
  647. \SeeAlso
  648. \seef{degtograd}, \seef{degtorad}, \seef{radtodeg},
  649. \seef{radtograd}, \seef{cycletorad}
  650. \end{function}
  651. \FPCexample{ex37}
  652. \begin{function}{radtodeg}
  653. \Declaration
  654. Function radtodeg(rad : float) : float;
  655. \Description
  656. \var{Radtodeg} converts its argument \var{rad} (an angle expressed in
  657. radians) to an angle in degrees.
  658. (180 degrees equals pi radians)
  659. \Errors
  660. None.
  661. \SeeAlso
  662. \seef{degtograd}, \seef{degtorad}, \seef{radtocycle},
  663. \seef{radtograd}, \seef{cycletorad}
  664. \end{function}
  665. \FPCexample{ex38}
  666. \begin{function}{radtograd}
  667. \Declaration
  668. Function radtograd(rad : float) : float;
  669. \Description
  670. \var{Radtodeg} converts its argument \var{rad} (an angle expressed in
  671. radians) to an angle in grads.
  672. (200 grads equals pi radians)
  673. \Errors
  674. None.
  675. \SeeAlso
  676. \seef{degtograd}, \seef{degtorad}, \seef{radtocycle},
  677. \seef{radtodeg}, \seef{cycletorad}
  678. \end{function}
  679. \FPCexample{ex39}
  680. \begin{function}{randg}
  681. \Declaration
  682. Function randg(mean,stddev : float) : float;
  683. \Description
  684. \var{randg} returns a random number which - when produced in large
  685. quantities - has a Gaussian distribution with mean \var{mean} and
  686. standarddeviation \var{stddev}.
  687. \Errors
  688. None.
  689. \SeeAlso
  690. \seef{mean}, \seef{stddev}, \seep{meanandstddev}
  691. \end{function}
  692. \FPCexample{ex40}
  693. \begin{procedure}{sincos}
  694. \Declaration
  695. Procedure sincos(theta : float;var sinus,cosinus : float);
  696. \Description
  697. \var{Sincos} calculates the sine and cosine of the angle \var{theta},
  698. and returns the result in \var{sinus} and \var{cosinus}.
  699. On Intel hardware, This calculation will be faster than making 2 calls
  700. to clculatet he sine and cosine separately.
  701. \Errors
  702. None.
  703. \SeeAlso
  704. \seef{arcsin}, \seef{arccos}.
  705. \end{procedure}
  706. \FPCexample{ex41}
  707. \begin{function}{sinh}
  708. \Declaration
  709. Function sinh(x : float) : float;
  710. \Description
  711. \var{Sinh} returns the hyperbolic sine of its argument \var{x}.
  712. \Errors
  713. \SeeAlso
  714. \seef{cosh}, \seef{arsinh}, \seef{tanh}, \seef{artanh}
  715. \end{function}
  716. \FPCexample{ex42}
  717. \begin{function}{stddev}
  718. \Declaration
  719. Function stddev(const data : array of float) : float;
  720. Function stddev(const data : PFloat; Const N : Integer) : float;
  721. \Description
  722. \var{Stddev} returns the standard deviation of the values in \var{Data}.
  723. It returns zero if there is only one value.
  724. The second form of the function accepts a pointer to an array of \var{N}
  725. values.
  726. \Errors
  727. None.
  728. \SeeAlso
  729. \seef{mean}, \seep{meanandstddev}, \seef{variance}, \seef{totalvariance}
  730. \end{function}
  731. \FPCexample{ex43}
  732. \begin{function}{sum}
  733. \Declaration
  734. Function sum(const data : array of float) : float;
  735. Function sum(const data : PFloat; Const N : Integer) : float;
  736. \Description
  737. \var{Sum} returns the sum of the values in the \var{data} array.
  738. The second form of the function accepts a pointer to an array of \var{N}
  739. values.
  740. \Errors
  741. None.
  742. \SeeAlso
  743. \seef{sumofsquares}, \seep{sumsandsquares}, \seef{totalvariance}
  744. , \seef{variance}
  745. \end{function}
  746. \FPCexample{ex44}
  747. \begin{function}{sumofsquares}
  748. \Declaration
  749. Function sumofsquares(const data : array of float) : float;
  750. Function sumofsquares(const data : PFloat; Const N : Integer) : float;
  751. \Description
  752. \var{Sumofsquares} returns the sum of the squares of the values in the \var{data}
  753. array.
  754. The second form of the function accepts a pointer to an array of \var{N}
  755. values.
  756. \Errors
  757. None.
  758. \SeeAlso
  759. \seef{sum}, \seep{sumsandsquares}, \seef{totalvariance}
  760. , \seef{variance}
  761. \end{function}
  762. \FPCexample{ex45}
  763. \begin{procedure}{sumsandsquares}
  764. \Declaration
  765. Procedure sumsandsquares(const data : array of float;
  766. var sum,sumofsquares : float);
  767. Procedure sumsandsquares(const data : PFloat; Const N : Integer;
  768. var sum,sumofsquares : float);
  769. \Description
  770. \var{sumsandsquares} calculates the sum of the values and the sum of
  771. the squares of the values in the \var{data} array and returns the
  772. results in \var{sum} and \var{sumofsquares}.
  773. The second form of the function accepts a pointer to an array of \var{N}
  774. values.
  775. \Errors
  776. None.
  777. \SeeAlso
  778. \seef{sum}, \seef{sumofsquares}, \seef{totalvariance}
  779. , \seef{variance}
  780. \end{procedure}
  781. \FPCexample{ex46}
  782. \begin{function}{tan}
  783. \Declaration
  784. Function tan(x : float) : float;
  785. \Description
  786. \var{Tan} returns the tangent of \var{x}.
  787. \Errors
  788. If \var{x} (normalized) is pi/2 or 3pi/2 then an overflow will occur.
  789. \SeeAlso
  790. \seef{tanh}, \seef{arcsin}, \seep{sincos}, \seef{arccos}
  791. \end{function}
  792. \FPCexample{ex47}
  793. \begin{function}{tanh}
  794. \Declaration
  795. Function tanh(x : float) : float;
  796. \Description
  797. \var{Tanh} returns the hyperbolic tangent of \var{x}.
  798. \Errors
  799. None.
  800. \SeeAlso
  801. \seef{arcsin}, \seep{sincos}, \seef{arccos}
  802. \end{function}
  803. \FPCexample{ex48}
  804. \begin{function}{totalvariance}
  805. \Declaration
  806. Function totalvariance(const data : array of float) : float;
  807. Function totalvariance(const data : PFloat; Const N : Integer) : float;
  808. \Description
  809. \var{TotalVariance} returns the total variance of the values in the
  810. \var{data} array. It returns zero if there is only one value.
  811. The second form of the function accepts a pointer to an array of \var{N}
  812. values.
  813. \Errors
  814. None.
  815. \SeeAlso
  816. \seef{variance}, \seef{stddev}, \seef{mean}
  817. \end{function}
  818. \FPCexample{ex49}
  819. \begin{function}{variance}
  820. \Declaration
  821. Function variance(const data : array of float) : float;
  822. Function variance(const data : PFloat; Const N : Integer) : float;
  823. \Description
  824. \var{Variance} returns the variance of the values in the
  825. \var{data} array. It returns zero if there is only one value.
  826. The second form of the function accepts a pointer to an array of \var{N}
  827. values.
  828. \Errors
  829. None.
  830. \SeeAlso
  831. \seef{totalvariance}, \seef{stddev}, \seef{mean}
  832. \end{function}
  833. \FPCexample{ex50}