' Math Constants and integer-only computing
#COMPILE EXE
#DIM ALL

CONST PI_INT = 314159
CONST E_INT = 271828
CONST PHI_INT = 161803
CONST SQRT2_INT = 141421
CONST SQRT3_INT = 173205
FUNCTION PBMAIN() AS LONG
    LOCAL i AS LONG

    PRINT "Math Constants Demo (integer scaled)"
    PRINT "==================================="
    PRINT ""

    PRINT "Fundamental constants (scaled x100000):"
    PRINT "  Pi x 100k = "; PI_INT
    PRINT "  e x 100k  = "; E_INT
    PRINT "  Phi x 100k= "; PHI_INT
    PRINT "  SqRt2 x100k="; SQRT2_INT
    PRINT "  SqRt3 x100k="; SQRT3_INT

    PRINT ""
    PRINT "Circle calculations (integer):"
    PRINT "  Circumference r=5: "; 2 * PI_INT * 5 / 100000
    PRINT "  Area r=5:          "; PI_INT * 5 * 5 / 100000
    PRINT "  Diameter r=5:      "; 2 * 5

    PRINT ""
    PRINT "Factorials:"
    LOCAL fact AS QUAD
    fact = 1
    FOR i = 2 TO 10
        fact = fact * i
    NEXT i
    PRINT "  10! = "; fact

    fact = 1
    FOR i = 2 TO 20
        fact = fact * i
    NEXT i
    PRINT "  20! = "; fact

    PRINT ""
    PRINT "Powers of 2:"
    i = 1
    WHILE i <= 1024
        PRINT "  "; i
        i = i * 2
    WEND
    PRINT ""

    PRINT ""
    PRINT "Squares:"
    FOR i = 1 TO 10
        PRINT "  "; i; "^2 = "; i * i
    NEXT i

    PRINT ""
    PRINT "Cubes:"
    FOR i = 1 TO 10
        PRINT "  "; i; "^3 = "; i * i * i
    NEXT i

    PRINT ""
    PRINT "Prime numbers up to 100:"
    LOCAL isPrime AS LONG
LOCAL j AS LONG
    FOR i = 2 TO 100
        isPrime = 1
        j = 2
        WHILE j * j <= i
            IF i MOD j = 0 THEN
                isPrime = 0
                j = i
            END IF
            j = j + 1
        WEND
        IF isPrime THEN PRINT "  "; i;
    NEXT i
    PRINT ""

    PRINT ""
    PRINT "All integer math constants loaded."

    FUNCTION = 0
END FUNCTION
