Q(uick)BASIC Function: EXP
Quick View
EXP
A math function that calculates the exponential function (e raised to the power of a numeric expression)
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- EXP(numeric-expression)
- LOG(numeric-expression)
Description/Parameter(s)
numeric-expression | For EXP, a number less than or equal to 88.02969. For LOG, any positive numeric expression. |
Example
PRINT EXP(0), EXP(1) 'Output is: 1 2.718282
PRINT LOG(1), LOG(EXP(1)) 'Output is: 0 1
Syntax
- EXP(numeric-expression)
Description/Parameter(s)
The EXP function returns e (the base of natural logarithms) to the power of x. The exponent x must be less than or equal to 88.02969. A value of x greater than 88.02969 produces an Overflow error message.
The calculation of EXP is performed in single precision by default; if the argument x is double precision, EXP is calculated in double precision.
Example
This example uses the EXP function to calculate the growth of a bacterial colony over a 15-day period. The program prompts you for an initial population and the rate of growth.
CLS ' Clear screen
INPUT "Initial bacterial population"; Colony0
INPUT "Growth rate per day as a percentage of population"; Rate
R = Rate / 100 : Form$ = "## ###,###,###,###"
PRINT : PRINT "Day Population"
FOR T = 0 TO 15 STEP 5
PRINT USING Form$; T, Colony0 * EXP(R * T)
NEXT
Sample Output:
Initial bacterial population? 10000 Growth rate per day as a percentage of population? 10 Day Population 0 10,000 5 16,487 10 27,183 15 44,817See also:
Syntax
- EXP(x)
Description/Parameter(s)
Usage Notes
- EXP is calculated in single precision if the exponent x is an integer or single-precision value. If you use any other numeric data type, EXP is calculated in double-precision.
- The exponent x must be less than or equal to 88.02969 when you are using single-precision values and less than or equal to 709.782712893 when you are using double-precision values. If you use a value of x that is not within those limits, BASIC produces the error message, "Overflow."
- The constant e is approximately equal to 2.718282.
Example
This example uses the EXP function to calculate the growth of a bacterial colony over a 15-day period. The program prompts you for an initial population and the rate of growth.
CLS 'Clear screen.
INPUT "Initial bacterial population"; Colony0
INPUT "Growth rate per day as a percentage of population"; Rate
R = Rate / 100: Form$ = "## ###,###,###,###"
PRINT : PRINT "Day Population"
FOR T = 0 TO 15 STEP 5
PRINT USING Form$; T; Colony0 * EXP(R * T)
NEXT
Sample Output:
Initial bacterial population? 10000 Growth rate per day as a percentage of population? 10 Day Population 0 10,000 5 16,487 10 27,183 15 44,817See also: