Sheerpower Logo

Common Math Functions


For transcendental functions like sin(), cos(), exp(), and log(), Sheerpower temporarily converts its internal REAL number to a standard DOUBLE, performs the operation, and then converts the result back to a REAL. This is acceptable because the results of these functions are irrational and cannot be represented exactly by any finite-precision data type.

For all other math operations, Sheerpower maintains its high-precision REAL data type throughout the calculation, ensuring maximum numeric accuracy wherever mathematically possible.

Core Math Functions

ABS() returns the absolute value of a number.

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

DIV0() 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() returns the fractional part of a number.

print fp(238.304) // Returns: 0.304

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

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

REMAINDER() returns the remainder of a division operation.

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

Trigonometric Functions

SIN() returns the sine of an angle.

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

COS() returns the cosine of an angle.

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

TAN() returns the tangent of an angle.

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

ASIN() returns the arcsine of a number.

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

ACOS() returns the arccosine of a number.

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

ATAN() returns the arctangent of a number.

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

ATN() also returns the arctangent of a number.

print atn(33) // Returns: 1.5405

ANGLE() returns the angle from (0,0) to (x,y) in radians.

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

Rounding and Integer Functions

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

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

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

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

INT() returns the whole portion of a REAL number as a REAL.

print int(148.8432) // Returns: 148

INTEGER() converts a numeric expression to an integer.

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

IP() truncates the decimal portion of a number.

print ip(1234.56) // Returns: 1234

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

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

TRUNCATE() cuts off digits after a specified decimal place.

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

Random Number Functions

RND() generates a random number.

print rnd // Returns: 0.94097 (example) print rnd(100) // Returns: 56 (example)
Note: The rnd() function returns a fraction between 0 and 1 when used without parameters. If a numeric argument is provided, it returns a whole number between 1 and that number. Use set seed NN to specify a repeatable sequence.

Conversion and Utility Functions

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

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

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

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

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

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

MIN() returns the smaller of two values.

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

MAX() returns the larger of two values.

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

CLAMP() restricts a value to a given range.

print clamp(15, 1, 10) // Returns: 10 print clamp(5, 1, 10) // Returns: 5 print clamp(-3, 1, 10) // Returns: 1

Sheerpower provides a wide range of additional built-in math functions. Most operate directly on its REAL data type to preserve precision throughout. For a complete reference, see the documentation 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.