Home > CBM > BASIC > Keywords > Abs 180 Subpages: (divide), (equal), (less), (minus), (more), (multiply), (plus), (power), 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, 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 | | ABS | A{Shift+B} | B6 | 1.0+ | Function |
ABS ( value ) | Parameters | Type | Legal Value(s) | Default Value | Note(s) | | value | Numeric | any | | |
| Returns | Type | Value(s) | Note(s) | | result | Floating-point | any non-negative | |
Calculate the absolute value of a number.
The ABS function simply returns the value with sign "changed" to positive. Of course if the original value was not negative, the result is the same as the original value. This function would be more useful if CBM BASIC supported complex numbers. But even limited to real numbers, it comes in handy, and is MUCH faster than calculating SQR(value*value). Use it when you want to ensure a number is positive (as required by some functions). Also useful for working with polar coordinates or implementing complex numbers. You will get TYPE MISMATCH ERROR with a string value. If value is missing or not a valid expression, SYNTAX ERROR is generated. Examples:
PRINT ABS(2)
2
READY.
PRINT ABS(-2)
2
READY.
|
© H2Obsession, 2014 |