High-precision mathematical calculator written in modern Fortran
FORTBITE (Fortran-based Operations on Real-Time Backend for Interactive Technical Expression) is a scientific calculator featuring arbitrary precision arithmetic, complex number support, matrix operations, and a comprehensive mathematical function library. Native Fortran 2008+ implementation with a clean REPL interface.
fortbite is available for Fedora/RHEL as an RPM package, and can be built from source using Make or the Fortran Package Manager (fpm).
Launch fortbite to enter the interactive REPL (Read-Eval-Print Loop):
fortbite has no configuration files. All settings are controlled at runtime through commands and expression syntax. This keeps the tool simple and portable.
Default precision is double precision (15-16 significant digits). Output precision
can be customized per-expression using the :: operator.
When building from source, compiler flags can be modified in the Makefile:
| Option | Type | Default | Description |
|---|---|---|---|
pi | constant | 3.14159... | Circle constant (4 * atan(1)) |
e | constant | 2.71828... | Euler's number (exp(1)) |
i | constant | sqrt(-1) | Imaginary unit |
fortbite is a high-precision mathematical calculator designed for scientific computing, engineering calculations, and mathematical education. It provides a clean interactive interface with support for complex numbers, matrices, and a comprehensive function library.
fortbite evaluates mathematical expressions using standard notation. Expressions can include numbers, operators, functions, variables, and parentheses for grouping.
Select a subtopic from the sidebar to learn about arithmetic operations, operator precedence, and variable management.
fortbite supports standard arithmetic operations with proper mathematical order of operations (PEMDAS):
Operators are evaluated in this order (highest to lowest precedence):
(), []sin(), det()^, ** (right-associative)*, /, %+, -:=::
Use the := operator to assign values to variables:
x is different from Xfortbite provides a comprehensive library of mathematical functions covering trigonometry, exponentials, logarithms, and special functions.
Select a subtopic from the sidebar to explore the available functions.
All trigonometric functions use radians:
| Option | Type | Default | Description |
|---|---|---|---|
sin(x) | function | - | Sine (radians) |
cos(x) | function | - | Cosine (radians) |
tan(x) | function | - | Tangent (radians) |
asin(x) | function | - | Inverse sine (alias: arcsin) |
acos(x) | function | - | Inverse cosine (alias: arccos) |
atan(x) | function | - | Inverse tangent (alias: arctan) |
sec(x) | function | - | Secant |
csc(x) | function | - | Cosecant |
cot(x) | function | - | Cotangent |
| Option | Type | Default | Description |
|---|---|---|---|
sinh(x) | function | - | Hyperbolic sine |
cosh(x) | function | - | Hyperbolic cosine |
tanh(x) | function | - | Hyperbolic tangent |
asinh(x) | function | - | Inverse hyperbolic sine |
acosh(x) | function | - | Inverse hyperbolic cosine |
atanh(x) | function | - | Inverse hyperbolic tangent |
| Option | Type | Default | Description |
|---|---|---|---|
exp(x) | function | - | e^x |
exp2(x) | function | - | 2^x |
exp10(x) | function | - | 10^x |
log(x) | function | - | Natural logarithm (alias: ln) |
log10(x) | function | - | Base-10 logarithm (alias: lg) |
log2(x) | function | - | Base-2 logarithm |
expm1(x) | function | - | exp(x) - 1 (accurate for small x) |
| Option | Type | Default | Description |
|---|---|---|---|
sqrt(x) | function | - | Square root |
abs(x) | function | - | Absolute value / magnitude |
factorial(n) | function | - | n! (alias: fact) |
gamma(x) | function | - | Gamma function |
lgamma(x) | function | - | Log-gamma (alias: loggamma) |
erf(x) | function | - | Error function |
erfc(x) | function | - | Complementary error function |
floor(x) | function | - | Floor (round down) |
ceil(x) | function | - | Ceiling (round up) |
round(x) | function | - | Nearest integer (alias: nint) |
frac(x) | function | - | Fractional part (alias: fraction) |
fortbite provides full support for complex number arithmetic and functions. Complex numbers can be created using multiple syntaxes.
Select a subtopic to learn about creating and operating on complex numbers.
Multiple syntaxes are supported:
| Option | Type | Default | Description |
|---|---|---|---|
real(z) | function | - | Real part (alias: re) |
imag(z) | function | - | Imaginary part (alias: im) |
conj(z) | function | - | Complex conjugate (alias: conjugate) |
abs(z) | function | - | Magnitude (aliases: cabs, modulus) |
arg(z) | function | - | Phase angle (aliases: phase, angle) |
cmplx(a,b) | function | - | Create complex from real parts |
fortbite supports matrices of arbitrary size with full linear algebra operations.
Select a subtopic to learn about creating matrices, linear algebra functions, and statistical operations.
Matrices are created using square brackets with semicolons separating rows:
| Option | Type | Default | Description |
|---|---|---|---|
zeros(m,n) | function | - | m x n zero matrix |
ones(m,n) | function | - | m x n ones matrix |
eye(n) | function | - | n x n identity matrix |
diag(v) | function | - | Diagonal matrix from vector |
transpose(A) | function | - | Matrix transpose |
det(A) | function | - | Determinant |
inv(A) | function | - | Matrix inverse |
trace(A) | function | - | Sum of diagonal elements |
rank(A) | function | - | Matrix rank |
solve(A,b) | function | - | Solve Ax = b |
sum(M) | function | - | Sum all elements |
mean(M) | function | - | Mean (alias: average) |
std(M) | function | - | Standard deviation (alias: stddev) |
The :: operator specifies output precision (decimal digits):
Note: The :: operator only affects output formatting.
Internal calculations always use double precision (~15 significant digits).
fortbite is implemented in approximately 28,000 lines of modern Fortran (2008+) across 11 modules plus the main program. The architecture follows a classic compiler design pattern: lexer ā parser ā evaluator.
fortbite/
āāā src/
ā āāā fortbite.f90 # Main program (REPL entry)
ā āāā fortbite_precision_m.f90 # Precision management
ā āāā fortbite_types_m.f90 # Core data types
ā āāā fortbite_lexer_m.f90 # Tokenization
ā āāā fortbite_ast_m.f90 # Abstract Syntax Tree
ā āāā fortbite_parser_m.f90 # Parsing
ā āāā fortbite_evaluator_m.f90 # Expression evaluation
ā āāā fortbite_arithmetic_m.f90 # Arithmetic operations
ā āāā fortbite_functions_m.f90 # Math function library
ā āāā fortbite_matrix_m.f90 # Linear algebra
ā āāā fortbite_io_m.f90 # REPL interface
āāā test/ # Test suite
The lexer (fortbite_lexer_m.f90) converts input strings into
token streams. It recognizes:
+, -, *, /, ^, **, %(, ), [, ], ;, ,, :=, ::i
The parser (fortbite_parser_m.f90) builds Abstract Syntax Trees
from token streams using recursive descent with precedence climbing.
AST_LITERAL - Constant valuesAST_IDENTIFIER - Variable/constant namesAST_BINARY_OP - Binary operationsAST_UNARY_OP - Unary operationsAST_FUNCTION_CALL - Function invocationsAST_ASSIGNMENT - Variable assignmentAST_PRECISION_SPEC - Precision specificationAST_MATRIX_LITERAL - Matrix notation
The evaluator (fortbite_evaluator_m.f90) executes ASTs with
automatic type promotion:
The evaluator maintains a symbol table (linked list) for variable storage and dispatches function calls to specialized evaluation routines.
The value_t type is the universal value container:
type :: value_t
integer :: value_type ! SCALAR, COMPLEX, MATRIX
! Union-like storage
real(real64) :: scalar_val
complex(real64) :: complex_val
real(real64), allocatable :: matrix_val(:,:)
complex(real64), allocatable :: complex_matrix_val(:,:)
! Matrix metadata
integer :: rows, cols
logical :: is_complex_matrix
end type value_t User Input
ā
āāāāāāāāāāāāāāāāāāāāāāā
ā I/O (fortbite_io_m) ā ā Read input, check if command
āāāāāāāāāāāā¬āāāāāāāāāāā
ā
āāāāāāāāāāāāāāāāāāāāāā
ā Lexer (lexer_m) ā ā Tokenize input string
āāāāāāāāāāā¬āāāāāāāāāāā
ā
āāāāāāāāāāāāāāāāāāāāāāāāā
ā Parser (parser_m) ā ā Build AST from tokens
āāāāāāāāāāāā¬āāāāāāāāāāāāā
ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Evaluator (evaluator_m) ā
ā āā Arithmetic (arithmetic_m) ā
ā āā Functions (functions_m) ā
ā āā Matrix ops (matrix_m) ā
ā āā Variables (symbol table) ā
āāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāā
ā
āāāāāāāāāāāāāāāāāāāāāāāā
ā Result (value_t) ā ā Scalar, Complex, or Matrix
āāāāāāāāāāāā¬āāāāāāāāāāāā
ā
Display | Option | Type | Default | Description |
|---|---|---|---|
help | command | - | Display help information (aliases: h, ?) |
exit | command | - | Exit the calculator (aliases: quit, q) |
clear | command | - | Clear the screen (alias: cls) |
precision | command | - | Show current precision settings |
info | command | - | Display system information |
vars | command | - | List all defined variables (alias: variables) |
| Option | Type | Default | Description |
|---|---|---|---|
+ | operator | - | Addition |
- | operator | - | Subtraction / Unary negation |
* | operator | - | Multiplication / Matrix multiplication |
/ | operator | - | Division |
^ | operator | - | Exponentiation (right-associative) |
** | operator | - | Exponentiation (alias for ^) |
% | operator | - | Modulo (remainder) |
:= | operator | - | Variable assignment |
:: | operator | - | Precision specification |
| Option | Type | Default | Description |
|---|---|---|---|
sin(x) | function | - | Sine (radians) |
cos(x) | function | - | Cosine (radians) |
tan(x) | function | - | Tangent (radians) |
asin(x) | function | - | Inverse sine (alias: arcsin) |
acos(x) | function | - | Inverse cosine (alias: arccos) |
atan(x) | function | - | Inverse tangent (alias: arctan) |
sec(x) | function | - | Secant |
csc(x) | function | - | Cosecant |
cot(x) | function | - | Cotangent |
| Option | Type | Default | Description |
|---|---|---|---|
exp(x) | function | - | e^x |
exp2(x) | function | - | 2^x |
exp10(x) | function | - | 10^x |
log(x) | function | - | Natural logarithm (alias: ln) |
log10(x) | function | - | Base-10 logarithm (alias: lg) |
log2(x) | function | - | Base-2 logarithm |
expm1(x) | function | - | exp(x) - 1 (accurate for small x) |
| Option | Type | Default | Description |
|---|---|---|---|
sqrt(x) | function | - | Square root |
abs(x) | function | - | Absolute value / magnitude |
factorial(n) | function | - | n! (alias: fact) |
gamma(x) | function | - | Gamma function |
lgamma(x) | function | - | Log-gamma (alias: loggamma) |
erf(x) | function | - | Error function |
erfc(x) | function | - | Complementary error function |
floor(x) | function | - | Floor (round down) |
ceil(x) | function | - | Ceiling (round up) |
round(x) | function | - | Nearest integer (alias: nint) |
frac(x) | function | - | Fractional part (alias: fraction) |
| Option | Type | Default | Description |
|---|---|---|---|
real(z) | function | - | Real part (alias: re) |
imag(z) | function | - | Imaginary part (alias: im) |
conj(z) | function | - | Complex conjugate (alias: conjugate) |
abs(z) | function | - | Magnitude (aliases: cabs, modulus) |
arg(z) | function | - | Phase angle (aliases: phase, angle) |
cmplx(a,b) | function | - | Create complex from real parts |
| Option | Type | Default | Description |
|---|---|---|---|
zeros(m,n) | function | - | m x n zero matrix |
ones(m,n) | function | - | m x n ones matrix |
eye(n) | function | - | n x n identity matrix |
diag(v) | function | - | Diagonal matrix from vector |
transpose(A) | function | - | Matrix transpose |
det(A) | function | - | Determinant |
inv(A) | function | - | Matrix inverse |
trace(A) | function | - | Sum of diagonal elements |
rank(A) | function | - | Matrix rank |
solve(A,b) | function | - | Solve Ax = b |
sum(M) | function | - | Sum all elements |
mean(M) | function | - | Mean (alias: average) |
std(M) | function | - | Standard deviation (alias: stddev) |
| Option | Type | Default | Description |
|---|---|---|---|
pi | constant | 3.14159... | Circle constant (4 * atan(1)) |
e | constant | 2.71828... | Euler's number (exp(1)) |
i | constant | sqrt(-1) | Imaginary unit |
Cause: GCC Fortran compiler not installed.
Cause: Modules compiled out of order or parallel build race condition.
Matrix inversion is O(n³). For very large matrices, operations become slow.
solve(A,b) instead of inv(A)*b (more efficient)Very high precision (1000+ digits) takes longer to compute: