RosettaCodeData/Task/Real-constants-and-functions/QBasic/real-constants-and-function...

31 lines
980 B
Plaintext

'ceiling and floor easily implemented as functions.
'e & pi not available- calculate as shown.
FUNCTION ceiling (x)
IF x < 0 THEN ceiling = INT(x) ELSE ceiling = INT(x) + 1
END FUNCTION
FUNCTION floor (x)
IF x > 0 THEN
floor = INT(x)
ELSE
IF x <> INT(x) THEN floor = INT(x) - 1 ELSE floor = INT(x)
END IF
END FUNCTION
PRINT "e = "; EXP(1) ' e not available
PRINT "PI = "; 4 * ATN(1) ' pi not available
x = 12.345: y = 1.23
PRINT "sqrt = "; SQR(x), x ^ .5 ' square root- NB the unusual name
PRINT "ln = "; LOG(x) ' natural logarithm base e
PRINT "log10 = "; LOG(x) / 2.303 ' base 10 logarithm
PRINT "log = "; LOG(x) / LOG(y) ' arbitrary base logarithm
PRINT "exp = "; EXP(x) ' exponential
PRINT "abs = "; ABS(-x) ' absolute value
PRINT "floor = "; floor(x) ' floor
PRINT "ceil = "; ceiling(x) ' ceiling
PRINT "power = "; x ^ y ' power
END