| Home CBM ASCII-X BASIC Disk Commands Enter RUN mode Program Format Secret Variables Variable Format Expressions Keywords (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 Exp 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 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 Syntax Tokens C128 D64plus Disk Escape Codes Hardware PCxface PETSCII Pet2asc Futurama IBM PC-AT Contact Games Glossary Hall of fame Hall of shame Miscellaneous Privacy policy Programming Twisty puzzles |
EXP ( power )
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:
EXP is the inverse of the LOG function. Examples:
© H2Obsession, 2014 |