Home > CBM > BASIC > Keywords > Exp 180 Subpages: (divide), (equal), (less), (minus), (more), (multiply), (plus), (power), Abs, And, Append, Asc, Atn, Auto, Backup, Bank, Begin, Bend, Bload, Boot, Box, Bsave, Bump, Catalog, Char, Chr, Circle, Close, Clr, Cmd, Collect, Collision, Color, Concat, Cont, Copy, Cos, Data, Dclear, Dclose, Dec, Def, Delete, Dim, Directory, Dispose, Dload, Do, Dopen, Draw, Ds, Ds string, Dsave, Dverify, El, Else, End, Envelope, Er, Err, Exit, Fast, Fetch, Filter, Fn, For, Fre, Get, Get num, Getkey, Go, Gosub, Goto, Graphic, Gshape, Header, Help, Hex, If, Input, Input num, Instr, Int, Joy, Key, Left, Len, Let, List, Load, Locate, Log, Loop, Mid, Monitor, Movspr, New, Next, Not, Off, On, Open, Or, Paint, Peek, Pen, Pi, Play, Pointer, Poke, Pos, Pot, Print, Print num, Pudef, Quit, Rclr, Rdot, Read, Record, Rem, Rename, Renumber, Restore, Resume, Return, Rgr, Right, Rlum, Rnd, Rreg, Rspcolor, Rsppos, Rsprite, Run, Rwindow, Save, Scale, Scnclr, Scratch, Sgn, Sin, Sleep, Slow, Sound, Spc, Sprcolor, Sprdef, Sprite, Sprsav, Sqr, Sshape, St, Stash, Step, Stop, Str, Swap, Sys, Tab, Tan, Tempo, Then, Ti, Ti string, To, Trap, Troff, Tron, Until, Using, Usr, Val, Verify, Vol, Wait, While, Width, Window, Xor |
| Keyword | Abbreviation | Token (hex) | Version(s) | Classification | | EXP | E{Shift+X} | BD | 1.0+ | Function |
EXP ( power ) | Parameters | Type | Legal Value(s) | Note(s) | | power | Numeric | | |
| Returns | Type | Value(s) | Note(s) | | result | Floating-point | 0 to 1.70141183e+38 | |
Calculate a power of e. 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.
|
© H2Obsession, 2014 |