Files
five/examples/frb_mathlib.prg
Charles KWON OhJun 59568f3301 Five v0.9 — Harbour + Go fusion language
- Compiler: PP → Lexer → Parser → Analyzer → Gengo pipeline
- Parser: 232/236 (98%) Harbour compatibility, registry-based dispatch
- RTL: 351 Harbour-compatible functions
- RDD: DBF/NTX/CDX engines with Rushmore bitmap optimization
- Go Interop: IMPORT + pkg.Func() + obj:Method() with FastPath (15M calls/sec)
- HB_FUNC API: Full Harbour C API compatible Go bridge
- Concurrency: SPAWN/LAUNCH/GOROUTINE, <-, WATCH, PARALLEL FOR, ASYNC/AWAIT
- Extensions: Multi-return, DEFER, Slice, f-string, Nil-safe ?:, CONST
- Macro Compiler: Runtime AST parsing and evaluation
- Debugger: TUI debugger with source display, breakpoints, stepping
- FRB: Native + Pcode dual mode runtime binary
- Tests: 13 packages ALL PASS

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 09:41:50 +09:00

54 lines
945 B
Plaintext

// FRB Math Library — pre-compiled module loaded at runtime
// Build: five frb examples/frb_mathlib.prg -o mathlib.frb
// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com)
FUNCTION CircleArea(nRadius)
RETURN 3.14159265 * nRadius * nRadius
FUNCTION Fibonacci(n)
LOCAL a := 0, b := 1, i, temp
IF n <= 0
RETURN 0
ENDIF
IF n = 1
RETURN 1
ENDIF
FOR i := 2 TO n
temp := a + b
a := b
b := temp
NEXT
RETURN b
FUNCTION IsPrime(n)
LOCAL i
IF n < 2
RETURN .F.
ENDIF
IF n = 2
RETURN .T.
ENDIF
IF n % 2 = 0
RETURN .F.
ENDIF
FOR i := 3 TO Int(Sqrt(n)) STEP 2
IF n % i = 0
RETURN .F.
ENDIF
NEXT
RETURN .T.
FUNCTION Factorial(n)
IF n <= 1
RETURN 1
ENDIF
RETURN n * Factorial(n - 1)
FUNCTION GCD(a, b)
DO WHILE b != 0
LOCAL temp := b
b := a % b
a := temp
ENDDO
RETURN a