DELPHI
STUDY NOTES
MathWithMegan
, Click here for the complete
PowerPoint documents:
IT Grade 11 - Delphi
Delphi Programming
Chapter One :
Math Revision
MathWithMegan
, 1.2
Math Functions
, Notes
✓ When you use any mathematical function, you need to
add the word Math to the Uses section of the code. Like
so:
Syntax
Each function will include:
✓ The function keyword
✓ The function name (Ex. Random)
✓ The data required by the function (Ex. const aRange: integer)
✓ The return type of the function (Ex. :integer)
, SQRT ROUND TRUNC
✓ Calculates the square root of a ✓ Rounds a real number ✓ Removes or ‘chops
number. to the nearest integer off’ the decimal
✓ Only positive numbers number. part of a real
✓ Returns real number number.
✓ It returns an integer
after
✓ It does not round
the number
SQR
✓ Calculates the square of a number
✓ Number can be positive or negative
, FRAC Floor
✓ Returns the decimal part of a real ✓ The Floor function rounds a real
number. number down to the lowest integer
✓ It returns a real number. value.
Ceil
✓ The Ceil function rounds a real Pi
number up to the highest integer
value. ✓ PI is a predefined constant (variable
that can’t be changed) that returns
a real number giving a rough value
of Pi
, POWER
✓ The POWER function raises a base to a power
and returns a real answer
✓ Both the base and power are real numbers
, Random
✓ Generate random numbers.
✓ Returns a value between 0 and 1
✓ Returns a value between 0 and 10
✓ The number (10) is excluded. Meaning you'll get numbers 1-9
✓ Alternative: RandomRange
✓ Delphi will often generate the same random number every
time you run the program unless you use the RANDOMIZE
command before generating a random number.
✓ Random Range gives a random number between 2 numbers
✓ The second number is not included
, 1.2
Math Procedures
, Notes
✓ A procedure is also a pre-written subroutine designed to
perform a specific purpose
✓ Procedures do not return a value like functions do, but
instead