Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

EXP

Keyword Abbreviation Token (hex) Version(s) Classification
EXP E{Shift+X} BD 1.0+ Function

  Syntax  
EXP power )
 
Parameters Type Legal Value(s) Note(s)
power Numeric
88.0296919 or less
 
Returns Type Value(s) Note(s)
result Floating-point
0 to 1.70141183e+38
 
  Purpose  
Calculate a power of e.
 
  Remarks  
The EXP function is (conceptually) a special case of the power operator (^) using a constant base of e.  In math symbols, it simply calculates result in the equation
 result = e power
where e is the "natural" base of approximately 2.71828183.  In other words, if you defined a BASIC variable E with that value then you could write this:
 result = E ^ power
 
The way CBM BASIC is written, it is faster and more accurate to use the EXP function.  If the power is omitted or not a valid expression, SYNTAX ERROR is generated.  If power is not numeric, TYPE MISMATCH ERROR occurs.  If power is not a legal value (as shown above) then an OVERFLOW ERROR occurs.  Note that power less than about -88 will "underflow" and BASIC will return a zero result (as opposed to an error).
 
Humans typically use a base of 10 (for example, in floating-point numbers like 1.2E+6 also called "scientific notation").  Because BASIC lets you enter numbers in scientific format, you should rarely need to use either the power operator or the EXP function for working with base 10.  Computers often find a base of 2 to be convenient (imagine that!).  Use the power operator to calculates exponents with a base of 2.  If you use them a lot (particularly integer powers), you should store the results in an array.
 
If you're wondering about the "natural" base of e, it derives from many scientific formulas, involving things like bacteria population growth, charging of capacitors, and radioactive decay.  It is also used to define the "hyperbolic functions".  BASIC does not have any built-in hyperbolic functions, but here are some you can calculate:
 
Name Formula Legal Values (x) Range of result
hyperbolic sine; SINH(X) ( EXP(X)-EXP(-X) )/2
-88.0296919 to +88.0296919
-8.50705917e37 to +8.50705917e37
hyperbolic cosine; COSH(X) ( EXP(X)+EXP(-X) )/2
-88.0296919 to +88.0296919
1 to 8.50705917e37
hyperbolic tangent; TANH(X) ( EXP(2*X)-1 )/( EXP(2*X)+1 )
-88.0296919 to +88.0296919
-1 to 1
hyperbolic secant; SECH(X) 2/( EXP(X)+EXP(-X) )
-88.0296919 to +88.0296919
1.17549435e-38 to 1
hyperbolic cosecant; CSCH(X) 2/( EXP(X)-EXP(-X) )
-88.0296919 to +88.0296919
except ABS(X) < 2.32830642e-10 
-4.2949673e+9 to +3.3217874e+9
hyperbolic cotangent; COTH(X) ( EXP(2*X)+1 )/( EXP(2*X)-1 )
-4.25352958e+37 to +44.0148459
except ABS(X) < 2.02362794e-10
-4.42949673e+9 to -1
+1 to +4.42949673e+9
  
EXP is the inverse of the LOG function.
 
Examples:
PRINT EXP(0) : REM calculate e ^ 0
 1
 
READY.
PRINT EXP(1) : REM calculate e ^ 1
 2.71828183

READY.
PRINT EXP(10) : REM tenth power of e 
 22026.4658

READY.
 
  Compare With  
*, ^
 
  Contrast With  
 
  See Also  
ATN 

© H2Obsession, 2014
Comments