Sheerpower Logo
G.2  Common Math Functions
Below are the math functions provided by Sheerpower

The ABS() function returns the absolute value of a number.

print abs(-10) // Returns: 10 print abs(10) // Returns: 10

The ACOS() function returns the arccosine of a number.

print acos(1) // Returns: 0 print acos(0) // Returns: 1.5708 (pi/2)

The ASIN() function returns the arcsine of a number.

print asin(0) // Returns: 0 print asin(1) // Returns: 1.5708 (pi/2)

The ATAN() function returns the arctangent of a number.

print atan(0) // Returns: 0 print atan(1) // Returns: 0.7854 (pi/4)

The CEIL() function returns the smallest integer greater than or equal to a number.

print ceil(2.3) // Returns: 3 print ceil(-2.3) // Returns: -2

The COS() function returns the cosine of an angle.

print cos(0) // Returns: 1 print cos(1.5708) // Returns: 0 (approximately)

The EXP() function returns e raised to the power of a number.

print exp(1) // Returns: 2.7183 (approximately) print exp(0) // Returns: 1

The FLOOR() function returns the largest integer less than or equal to a number.

print floor(2.7) // Returns: 2 print floor(-2.7) // Returns: -3

The LOG() function returns the natural logarithm (base e) of a number.

print log(1) // Returns: 0 print log(2.7183) // Returns: 1 (approximately)

The MIN() function returns the minimum value among its arguments.

print min(3, 2) // Returns: 2 print min(-1, -5) // Returns: -5

The POW() function returns a number raised to the power of another number.

print pow(2, 3) // Returns: 8 print pow(5, 2) // Returns: 25

The SIN() function returns the sine of an angle.

print sin(0) // Returns: 0 print sin(1.5708) // Returns: 1 (approximately)

The SQRT() function returns the square root of a number.

print sqrt(4) // Returns: 2 print sqrt(16) // Returns: 4

The TAN() function returns the tangent of an angle.

print tan(0) // Returns: 0 print tan(0.7854) // Returns: 1 (approximately, pi/4)

DIV0() Function

The DIV0() function divides two numbers and returns 0 if the divisor is 0.

print div0(0.8, 0.000004) // Returns: 200000 print div0(0.8, 0.0) // Returns: 0 print div0(6, 3) // Returns: 2 print div0(6, 0) // Returns: 0

FP() Function

The FP() function returns the fractional part of a number.

print fp(238.304) // Returns: 0.304

INT() Function

The INT() function returns the whole portion of a real number as a real number.

print int(148.8432) // Returns: 148

INTEGER() Function

The INTEGER() function converts a numeric expression to an integer value.

z = integer(4 + (993 * 35)) print z // Returns: 34759

IP() Function

The IP() function truncates the value of a real number at the decimal point and returns the integer portion.

print ip(1234.56) // Returns: 1234

MAX() Function

The MAX() function returns the larger of two values.

print max(5, 9) // Returns: 9

MIN() Function

The MIN() function returns the lesser of two values.

x = 43 y = 19 print min(x, y) // Returns: 19

MOD() Function

The MOD() function returns the remainder of one number divided by another.

print mod(36, 13) // Returns: 10

REAL() Function

The REAL() function converts a numeric expression to a REAL value.

input 'Your age': age% let decimal_age = real(age%) print 'Your number is'; decimal_age // Returns: Your age? 31 Your number is 31

REMAINDER() Function

The REMAINDER() function returns the remainder when one number is divided by another.

print remainder(-4, 3) // Returns: -1

RND() Function

Sheerpower provides a simple and efficient way to generate random numbers using the rnd() function.

Example:

random_number = rnd(100)

This single line of code generates a random integer between 1 and 100, inclusive.

When you want to generate a random number within a specific range (e.g., 1 to 100), simply passing the upper limit of the range to rnd() is all you need. There's no need for additional calculations or adjustments.

Note: The rnd() function automatically starts at 1 and goes up to the number specified (inclusive), making it perfect for generating random numbers within a defined range.

The RND function (without any parameter) returns a random fraction. If a numeric expression is given as an argument, returns a whole number between one and the numeric expression.

Optionally, SET SEED NN statement can be used to specify a specific random sequence of NN, otherwise the sequence itself is chosen by a random system time event.

print rnd // Returns: 0.9409720199182629 (example) print rnd(100) // Returns 56 (example)

ROUND() Function

The ROUND() function rounds a number to the specified number of decimal places.

print round(21.83492, 2) // Returns: 21.83

TRUNCATE() Function

The TRUNCATE() function truncates a real number to a given number of decimal places.

print truncate(123.45678, 2) // Returns: 123.45 print truncate(123.45678, 4) // Returns: 123.4567

ABS() Function

The ABS() function returns the absolute value of a specified numeric expression.

print abs(-5) // Returns: 5

ACOS() Function

The ACOS() function returns the arccosine of a number.

print acos(.75) // Returns: 0.722734247813

ANGLE() Function

The ANGLE() function, given X and Y coordinates, returns the angle from 0,0 in radians.

print angle(4, 9) // Returns: 1.152571997216

ASIN() Function

The ASIN() function returns the arcsine of a number.

print asin(.3) // Returns: 0.304692654015

ATN() Function

The ATN() function returns the arctangent of a number.

print atn(33) // Returns: 1.540502566876

Sheerpower includes a full set of common math functions. Most of these functions operate directly on Sheerpower's REAL data type. Detailed explanations of each function can be found here.

Hide Description

    

       


      

Enter or modify the code below, and then click on RUN

Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use.
Wide screen