BASIC Maths functions

From DenialWIKI
Jump to navigation Jump to search

SIN

SIN(X) returns the sine of an angle X given in radians.

COS

COS(X) returns the cosine of an angle X given in radians.

TAN

TAN(X) returns the tangent of an angle X given in radians.

ATN

X=ATN(Y) returns an angle X in radians, for which Y=TAN(X). It is an inverse function to TAN(X).

ABS

Returns the Absolute value of a number. In other words the magnitude of the number or it's distance from 0 on the number plane. Just as 7 is 7 away from zero, -7 is 7 away from zero just in the opposite direction. The most simplest way to understand this is that ABS removes the minus sign.

  Negative Numbers <-  |  -> Positive Numbers
                       |
 -7 -6 -5 -4 -3 -2 -1  0  1  2  3  4  5  6  7
  +--+--+--+--+--+--+--+--+--+--+--+--+--+--+
                       |

Example

PRINT ABS(7)
 7

READY.

PRINT ABS(-7)
 7

READY.

PRINT ABS(-0.1)
 .1

READY.

Note: it works for both Integers and Real (Floating Point) numbers.

INT

INT(X) converts a Floating point number X to the nearest Integer not greater than X.

Example:

PRINT INT(0.9)
 0

READY.

PRINT INT(1.3)
 1

READY.

PRINT INT(-2.3)
-3

READY.

For rounding purposes, add .5 to the argument before applying INT().

RND

Returns a pseudo random Floating Point number between 0 and 1

SGN

Returns the sign of a number. For negative numbers it returns -1 and for positive it returns 1. Zero is a special case as zero has no sign so SGN just returns 0.

PRINT SGN(-30)
-1

READY.

PRINT SGN(3.14)
 1

READY.
PRINT SGN(0)
 0

READY.

Note that ABS and SGN are complementary functions

PRINT ABS(-10) * SGN(-10)
-10

READY.

PRINT ABS(10) * SGN(10)
 10

READY.

SQR

Returns the Square Root of a number.

PRINT SQR(4)
 2

READY.

PRINT SQR(2)
 1.41421356

READY.

EXP

EXP(X) returns e=2.7182... to the power of X.


LOG

Returns the natural logarithm of a number loge it does not return log10. Since it is based on the number e passing e to log returns 1. It is the inverse function to EXP().

Example:

E=EXP(1)
PRINT E
2.71828183

READY.
PRINT LOG(E)
 1
READY.

LOG returns the number which must be given as the power to e to obtain it.

Check out the following program

10 FOR V = 1 TO 10
20 A = LOG (V)
30 PRINT EXP(A)
40 NEXT

RUN
 1
 2
 3
 4
 5
 6
 7
 8
 9
 10

READY.

Check these Wikipedia articles for more on logarithms and e