fortbite
A command-line calculator written in Fortran that handles arbitrary precision arithmetic, complex numbers, and matrices.
Building
make
Running
./build/bin/fortbite
Basic Usage
Arithmetic
fortbite> 2 + 3
5.0000000000000000
fortbite> 10 - 4 * 2
2.0000000000000000
fortbite> (10 - 4) * 2
12.000000000000000
fortbite> 2^8
256.00000000000000
fortbite> 27^(1/3)
3.0000000000000000
Precision Control
Specify output precision with ::digits
fortbite> pi
3.1415926535897931
fortbite> pi::10
3.1415926536
fortbite> pi::30
3.141592653589793115997963468544
fortbite> e::15
2.718281828459045
Variables
fortbite> x := 42
42.000000000000000
fortbite> y := x * 2
84.000000000000000
fortbite> x + y
126.00000000000000
Functions
Trigonometric
fortbite> sin(pi/2)
1.0000000000000000
fortbite> cos(0)
1.0000000000000000
fortbite> atan(1) * 4
3.1415926535897931
Logarithmic and Exponential
fortbite> log(e)
1.0000000000000000
fortbite> log10(1000)
3.0000000000000000
fortbite> exp(1)
2.7182818284590451
fortbite> 2^10
1024.0000000000000
Special Functions
fortbite> sqrt(2)
1.4142135623730951
fortbite> factorial(5)
120.00000000000000
fortbite> floor(3.7)
3.0000000000000000
fortbite> ceil(3.2)
4.0000000000000000
Complex Numbers
fortbite> (3 + 4i) * 2
6.0000000000000000+8.0000000000000000i
fortbite> abs(3 + 4i)
5.0000000000000000
fortbite> conj(3 + 4i)
3.0000000000000000-4.0000000000000000i
Matrices
fortbite> [1,2;3,4]
[2x2 matrix]
1.0000000000000000 2.0000000000000000
3.0000000000000000 4.0000000000000000
fortbite> A := [1,2;3,4]
[2x2 matrix]
1.0000000000000000 2.0000000000000000
3.0000000000000000 4.0000000000000000
fortbite> det(A)
-2.0000000000000000
fortbite> inv(A)
[2x2 matrix]
-2.0000000000000000 1.0000000000000000
1.5000000000000000 -0.50000000000000000
fortbite> eye(3)
[3x3 matrix]
1.0000000000000000 0.0000000000000000 0.0000000000000000
0.0000000000000000 1.0000000000000000 0.0000000000000000
0.0000000000000000 0.0000000000000000 1.0000000000000000
Available Functions
Math Functions
- Trigonometric:
sin,cos,tan,asin,acos,atan - Hyperbolic:
sinh,cosh,tanh - Logarithmic:
log,ln,log10,log2 - Exponential:
exp,exp2,exp10 - Rounding:
floor,ceil,round - Other:
sqrt,abs,factorial
Complex Functions
realorre- real partimagorim- imaginary partconj- complex conjugatearg- phase anglecabs- complex absolute value
Matrix Functions
zeros(m,n)- zero matrixones(m,n)- matrix of oneseye(n)- identity matrixdet- determinantinv- inversetranspose- matrix transpose
Constants
pi- 3.14159...e- 2.71828...i- imaginary unit
Operators
- Basic:
+,-,*,/ - Power:
^or** - Assignment:
:= - Precision:
::
Commands
help- show command listexitorquit- exit the calculatorclear- clear screenvars- list defined variables
Testing
Run the test suite:
make test
Run specific test categories:
make test-unit # Unit tests only
make test-integration # Integration tests only
Notes
- Calculations use double precision by default
- The
::precision operator only affects output formatting, not internal precision - Variable names are case-sensitive
- Matrix operations require compatible dimensions
View source
| 1 | # fortbite |
| 2 | |
| 3 | A command-line calculator written in Fortran that handles arbitrary precision arithmetic, complex numbers, and matrices. |
| 4 | |
| 5 | ## Building |
| 6 | |
| 7 | ```bash |
| 8 | make |
| 9 | ``` |
| 10 | |
| 11 | ## Running |
| 12 | |
| 13 | ```bash |
| 14 | ./build/bin/fortbite |
| 15 | ``` |
| 16 | |
| 17 | ## Basic Usage |
| 18 | |
| 19 | ### Arithmetic |
| 20 | ``` |
| 21 | fortbite> 2 + 3 |
| 22 | 5.0000000000000000 |
| 23 | |
| 24 | fortbite> 10 - 4 * 2 |
| 25 | 2.0000000000000000 |
| 26 | |
| 27 | fortbite> (10 - 4) * 2 |
| 28 | 12.000000000000000 |
| 29 | |
| 30 | fortbite> 2^8 |
| 31 | 256.00000000000000 |
| 32 | |
| 33 | fortbite> 27^(1/3) |
| 34 | 3.0000000000000000 |
| 35 | ``` |
| 36 | |
| 37 | ### Precision Control |
| 38 | |
| 39 | Specify output precision with `::digits` |
| 40 | ``` |
| 41 | fortbite> pi |
| 42 | 3.1415926535897931 |
| 43 | |
| 44 | fortbite> pi::10 |
| 45 | 3.1415926536 |
| 46 | |
| 47 | fortbite> pi::30 |
| 48 | 3.141592653589793115997963468544 |
| 49 | |
| 50 | fortbite> e::15 |
| 51 | 2.718281828459045 |
| 52 | ``` |
| 53 | |
| 54 | ### Variables |
| 55 | ``` |
| 56 | fortbite> x := 42 |
| 57 | 42.000000000000000 |
| 58 | |
| 59 | fortbite> y := x * 2 |
| 60 | 84.000000000000000 |
| 61 | |
| 62 | fortbite> x + y |
| 63 | 126.00000000000000 |
| 64 | ``` |
| 65 | |
| 66 | ### Functions |
| 67 | |
| 68 | #### Trigonometric |
| 69 | ``` |
| 70 | fortbite> sin(pi/2) |
| 71 | 1.0000000000000000 |
| 72 | |
| 73 | fortbite> cos(0) |
| 74 | 1.0000000000000000 |
| 75 | |
| 76 | fortbite> atan(1) * 4 |
| 77 | 3.1415926535897931 |
| 78 | ``` |
| 79 | |
| 80 | #### Logarithmic and Exponential |
| 81 | ``` |
| 82 | fortbite> log(e) |
| 83 | 1.0000000000000000 |
| 84 | |
| 85 | fortbite> log10(1000) |
| 86 | 3.0000000000000000 |
| 87 | |
| 88 | fortbite> exp(1) |
| 89 | 2.7182818284590451 |
| 90 | |
| 91 | fortbite> 2^10 |
| 92 | 1024.0000000000000 |
| 93 | ``` |
| 94 | |
| 95 | #### Special Functions |
| 96 | ``` |
| 97 | fortbite> sqrt(2) |
| 98 | 1.4142135623730951 |
| 99 | |
| 100 | fortbite> factorial(5) |
| 101 | 120.00000000000000 |
| 102 | |
| 103 | fortbite> floor(3.7) |
| 104 | 3.0000000000000000 |
| 105 | |
| 106 | fortbite> ceil(3.2) |
| 107 | 4.0000000000000000 |
| 108 | ``` |
| 109 | |
| 110 | ### Complex Numbers |
| 111 | ``` |
| 112 | fortbite> (3 + 4i) * 2 |
| 113 | 6.0000000000000000+8.0000000000000000i |
| 114 | |
| 115 | fortbite> abs(3 + 4i) |
| 116 | 5.0000000000000000 |
| 117 | |
| 118 | fortbite> conj(3 + 4i) |
| 119 | 3.0000000000000000-4.0000000000000000i |
| 120 | ``` |
| 121 | |
| 122 | ### Matrices |
| 123 | ``` |
| 124 | fortbite> [1,2;3,4] |
| 125 | [2x2 matrix] |
| 126 | 1.0000000000000000 2.0000000000000000 |
| 127 | 3.0000000000000000 4.0000000000000000 |
| 128 | |
| 129 | fortbite> A := [1,2;3,4] |
| 130 | [2x2 matrix] |
| 131 | 1.0000000000000000 2.0000000000000000 |
| 132 | 3.0000000000000000 4.0000000000000000 |
| 133 | |
| 134 | fortbite> det(A) |
| 135 | -2.0000000000000000 |
| 136 | |
| 137 | fortbite> inv(A) |
| 138 | [2x2 matrix] |
| 139 | -2.0000000000000000 1.0000000000000000 |
| 140 | 1.5000000000000000 -0.50000000000000000 |
| 141 | |
| 142 | fortbite> eye(3) |
| 143 | [3x3 matrix] |
| 144 | 1.0000000000000000 0.0000000000000000 0.0000000000000000 |
| 145 | 0.0000000000000000 1.0000000000000000 0.0000000000000000 |
| 146 | 0.0000000000000000 0.0000000000000000 1.0000000000000000 |
| 147 | ``` |
| 148 | |
| 149 | ## Available Functions |
| 150 | |
| 151 | ### Math Functions |
| 152 | - Trigonometric: `sin`, `cos`, `tan`, `asin`, `acos`, `atan` |
| 153 | - Hyperbolic: `sinh`, `cosh`, `tanh` |
| 154 | - Logarithmic: `log`, `ln`, `log10`, `log2` |
| 155 | - Exponential: `exp`, `exp2`, `exp10` |
| 156 | - Rounding: `floor`, `ceil`, `round` |
| 157 | - Other: `sqrt`, `abs`, `factorial` |
| 158 | |
| 159 | ### Complex Functions |
| 160 | - `real` or `re` - real part |
| 161 | - `imag` or `im` - imaginary part |
| 162 | - `conj` - complex conjugate |
| 163 | - `arg` - phase angle |
| 164 | - `cabs` - complex absolute value |
| 165 | |
| 166 | ### Matrix Functions |
| 167 | - `zeros(m,n)` - zero matrix |
| 168 | - `ones(m,n)` - matrix of ones |
| 169 | - `eye(n)` - identity matrix |
| 170 | - `det` - determinant |
| 171 | - `inv` - inverse |
| 172 | - `transpose` - matrix transpose |
| 173 | |
| 174 | ## Constants |
| 175 | - `pi` - 3.14159... |
| 176 | - `e` - 2.71828... |
| 177 | - `i` - imaginary unit |
| 178 | |
| 179 | ## Operators |
| 180 | - Basic: `+`, `-`, `*`, `/` |
| 181 | - Power: `^` or `**` |
| 182 | - Assignment: `:=` |
| 183 | - Precision: `::` |
| 184 | |
| 185 | ## Commands |
| 186 | - `help` - show command list |
| 187 | - `exit` or `quit` - exit the calculator |
| 188 | - `clear` - clear screen |
| 189 | - `vars` - list defined variables |
| 190 | |
| 191 | ## Testing |
| 192 | |
| 193 | Run the test suite: |
| 194 | ```bash |
| 195 | make test |
| 196 | ``` |
| 197 | |
| 198 | Run specific test categories: |
| 199 | ```bash |
| 200 | make test-unit # Unit tests only |
| 201 | make test-integration # Integration tests only |
| 202 | ``` |
| 203 | |
| 204 | ## Notes |
| 205 | |
| 206 | - Calculations use double precision by default |
| 207 | - The `::` precision operator only affects output formatting, not internal precision |
| 208 | - Variable names are case-sensitive |
| 209 | - Matrix operations require compatible dimensions |