CPSC 110 - Pascal Brent M. Dingle Texas A&M University Chapter 3 Finishing Chapter 3 CPSC 110 - Pascal Brent M. Dingle Texas A&M University Chapter 3
Predefined Functions Pascal, like most programming languages, offers a set of predefined functions. Unfortunately not all languages offer the same set of predefined functions. Some functions Pascal offers are: sqrt(x); - returns the square root of x abs(x); - returns the absolute value of x round(x) - rounds x to the nearest integer trunc(x) - truncates x to the nearest integer sqr(x) - returns x squared (i.e. x*x)
Natural Logarithm and e Pascal also offers the predefined functions: ln(x) exp(z) ln(x) returns the natural log of x. aside: natural log is log base e where e is approximately 2.71828. exp(z) returns e raised to the z power
ln and exp trick Suppose you wanted to set z = xy. We know xy = (eln(x))y = ey*(ln(x)). And ey*(ln(x)) = exp(y*ln(x)). So to set z = xy, we would say: z := exp( y * ln(x) );
End Predefines and ln and e