math-engine 0.3.2__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {math_engine-0.3.2 → math_engine-0.5.0}/PKG-INFO +137 -61
- {math_engine-0.3.2 → math_engine-0.5.0}/README.md +135 -60
- math_engine-0.5.0/math_engine/AST_Node_Types.py +184 -0
- {math_engine-0.3.2 → math_engine-0.5.0}/math_engine/__init__.py +5 -2
- {math_engine-0.3.2 → math_engine-0.5.0}/math_engine/calculator.py +258 -438
- math_engine-0.5.0/math_engine/cli.py +311 -0
- {math_engine-0.3.2 → math_engine-0.5.0}/math_engine/error.py +2 -0
- math_engine-0.5.0/math_engine/non_decimal_utility.py +240 -0
- math_engine-0.5.0/math_engine/utility.py +97 -0
- {math_engine-0.3.2 → math_engine-0.5.0}/math_engine.egg-info/PKG-INFO +137 -61
- {math_engine-0.3.2 → math_engine-0.5.0}/math_engine.egg-info/SOURCES.txt +5 -0
- math_engine-0.5.0/math_engine.egg-info/entry_points.txt +3 -0
- {math_engine-0.3.2 → math_engine-0.5.0}/pyproject.toml +5 -1
- {math_engine-0.3.2 → math_engine-0.5.0}/LICENSE +0 -0
- {math_engine-0.3.2 → math_engine-0.5.0}/math_engine/ScientificEngine.py +0 -0
- {math_engine-0.3.2 → math_engine-0.5.0}/math_engine/config.json +0 -0
- {math_engine-0.3.2 → math_engine-0.5.0}/math_engine/config_manager.py +0 -0
- {math_engine-0.3.2 → math_engine-0.5.0}/math_engine.egg-info/dependency_links.txt +0 -0
- {math_engine-0.3.2 → math_engine-0.5.0}/math_engine.egg-info/top_level.txt +0 -0
- {math_engine-0.3.2 → math_engine-0.5.0}/setup.cfg +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: math-engine
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: A fast and secure mathematical expression evaluator.
|
|
5
5
|
Author-email: Jan Teske <jan.teske.06@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/JanTeske06/math_engine
|
|
7
7
|
Project-URL: Source, https://github.com/JanTeske06/math_engine
|
|
8
|
+
Project-URL: Changelog, https://github.com/JanTeske06/math_engine/blob/master/CHANGELOG.md
|
|
8
9
|
Classifier: Programming Language :: Python :: 3
|
|
9
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
11
|
Classifier: Operating System :: OS Independent
|
|
@@ -13,7 +14,7 @@ Description-Content-Type: text/markdown
|
|
|
13
14
|
License-File: LICENSE
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
# Math Engine 0.
|
|
17
|
+
# Math Engine 0.5.0
|
|
17
18
|
|
|
18
19
|
[](https://pypi.org/project/math-engine/)
|
|
19
20
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -33,7 +34,7 @@ It provides a complete pipeline:
|
|
|
33
34
|
* Scientific functions
|
|
34
35
|
* Strict error codes for reliable debugging and automated testing
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
|
|
37
38
|
|
|
38
39
|
This library is ideal for:
|
|
39
40
|
|
|
@@ -62,7 +63,7 @@ This library is ideal for:
|
|
|
62
63
|
* `only_binary`
|
|
63
64
|
* `only_octal`
|
|
64
65
|
|
|
65
|
-
### Non-Decimal Support
|
|
66
|
+
### Non-Decimal Support
|
|
66
67
|
|
|
67
68
|
* Read binary `0b1101`
|
|
68
69
|
* Read octal `0o755`
|
|
@@ -79,7 +80,49 @@ This library is ideal for:
|
|
|
79
80
|
pip install math-engine
|
|
80
81
|
````
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
-----
|
|
84
|
+
|
|
85
|
+
# Command Line Interface (CLI)
|
|
86
|
+
|
|
87
|
+
Math Engine works directly from your terminal\! After installing via pip, you can use the command `math-engine` (or the short alias `calc`).
|
|
88
|
+
|
|
89
|
+
### 1\. Interactive Mode (REPL)
|
|
90
|
+
|
|
91
|
+
Start the shell to calculate, manage variables, and change settings dynamically.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
$ math-engine
|
|
95
|
+
|
|
96
|
+
Math Engine 0.4.0 Interactive Shell
|
|
97
|
+
Type 'help' for commands, 'exit' to leave.
|
|
98
|
+
----------------------------------------
|
|
99
|
+
Examples:
|
|
100
|
+
>>> 3 + 3 * 4
|
|
101
|
+
15
|
|
102
|
+
|
|
103
|
+
>>> hex: 255
|
|
104
|
+
0xff
|
|
105
|
+
|
|
106
|
+
>>> x + 5, x=10 (Inline Variables)
|
|
107
|
+
15
|
|
108
|
+
|
|
109
|
+
>>> set setting word_size 8
|
|
110
|
+
Setting updated: word_size -> 8
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 2\. Direct Calculation
|
|
114
|
+
|
|
115
|
+
You can also pass expressions directly (great for scripting):
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
$ math-engine "3 + 3"
|
|
119
|
+
6
|
|
120
|
+
|
|
121
|
+
$ math-engine "hex: 255"
|
|
122
|
+
0xff
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
-----
|
|
83
126
|
|
|
84
127
|
# Quick Start
|
|
85
128
|
|
|
@@ -123,17 +166,16 @@ math_engine.evaluate("bool: 3+3=6")
|
|
|
123
166
|
```python
|
|
124
167
|
import math_engine
|
|
125
168
|
|
|
126
|
-
reset_settings()
|
|
169
|
+
math_engine.reset_settings()
|
|
127
170
|
```
|
|
128
171
|
|
|
172
|
+
If a requested output type does not match the actual result, `correct_output_format=True` allows math\_engine to fall back to a compatible type instead of raising an error.
|
|
129
173
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
---
|
|
174
|
+
-----
|
|
133
175
|
|
|
134
176
|
# Prefix System (Casting Syntax)
|
|
135
177
|
|
|
136
|
-
|
|
178
|
+
math\_engine supports a powerful prefix-based casting system:
|
|
137
179
|
|
|
138
180
|
| Prefix | Meaning | Example |
|
|
139
181
|
| -------- | ----------- | ---------------------------------- |
|
|
@@ -153,7 +195,7 @@ math_engine.evaluate("hex: 3 + 3")
|
|
|
153
195
|
# '0x6'
|
|
154
196
|
```
|
|
155
197
|
|
|
156
|
-
|
|
198
|
+
-----
|
|
157
199
|
|
|
158
200
|
# Variables
|
|
159
201
|
|
|
@@ -176,7 +218,7 @@ math_engine.evaluate("A + B", A=10, B=5)
|
|
|
176
218
|
|
|
177
219
|
Variables are mapped internally to a safe internal representation and are designed to be simple and predictable.
|
|
178
220
|
|
|
179
|
-
|
|
221
|
+
-----
|
|
180
222
|
|
|
181
223
|
# Scientific Functions
|
|
182
224
|
|
|
@@ -190,7 +232,7 @@ math_engine.evaluate("pi * 2")
|
|
|
190
232
|
|
|
191
233
|
All functions are processed by the internal `ScientificEngine`, honoring your settings (for example, `use_degrees`).
|
|
192
234
|
|
|
193
|
-
|
|
235
|
+
-----
|
|
194
236
|
|
|
195
237
|
# Linear Equation Solver
|
|
196
238
|
|
|
@@ -201,11 +243,11 @@ math_engine.evaluate("x + 3 = 10")
|
|
|
201
243
|
|
|
202
244
|
Invalid or nonlinear equations produce errors with codes like:
|
|
203
245
|
|
|
204
|
-
* 3005 – Non-linear equation
|
|
205
|
-
* 3002 – Multiple variables
|
|
206
|
-
* 3022 – One side empty
|
|
246
|
+
* 3005 – Non-linear equation
|
|
247
|
+
* 3002 – Multiple variables
|
|
248
|
+
* 3022 – One side empty
|
|
207
249
|
|
|
208
|
-
|
|
250
|
+
-----
|
|
209
251
|
|
|
210
252
|
# Non-Decimal Numbers (Binary, Octal, Hex)
|
|
211
253
|
|
|
@@ -219,9 +261,9 @@ math_engine.evaluate("0b1010 * 3")
|
|
|
219
261
|
|
|
220
262
|
Non-decimal parsing respects the setting `allow_non_decimal`. If it is set to `False`, using `0b`, `0o`, or `0x` will raise a conversion error.
|
|
221
263
|
|
|
222
|
-
|
|
264
|
+
-----
|
|
223
265
|
|
|
224
|
-
# Bitwise Operations & Developer Mode (v0.
|
|
266
|
+
# Bitwise Operations & Developer Mode (v0.5.0)
|
|
225
267
|
|
|
226
268
|
Math Engine can act as a **programmer's calculator**. It supports standard operator precedence and bitwise logic.
|
|
227
269
|
|
|
@@ -242,15 +284,15 @@ Math Engine can act as a **programmer's calculator**. It supports standard opera
|
|
|
242
284
|
|
|
243
285
|
You can simulate hardware constraints (like C++ `int8`, `uint16`, etc.) by setting a `word_size`.
|
|
244
286
|
|
|
245
|
-
* **`word_size: 0` (Default):** Python mode (arbitrary precision, no overflow).
|
|
246
|
-
* **`word_size: 8/16/32/64`:** Enforces bit limits. Numbers will wrap around (overflow) accordingly.
|
|
287
|
+
* **`word_size: 0` (Default):** Python mode (arbitrary precision, no overflow).
|
|
288
|
+
* **`word_size: 8/16/32/64`:** Enforces bit limits. Numbers will wrap around (overflow) accordingly.
|
|
247
289
|
|
|
248
290
|
### Signed vs. Unsigned Mode
|
|
249
291
|
|
|
250
292
|
When `word_size > 0`, you can control how values are interpreted via `signed_mode`:
|
|
251
293
|
|
|
252
|
-
* **`True` (Default):** Use **Two's Complement** for negative values.
|
|
253
|
-
* **`False`:** Treat all values as unsigned.
|
|
294
|
+
* **`True` (Default):** Use **Two's Complement** for negative values.
|
|
295
|
+
* **`False`:** Treat all values as unsigned.
|
|
254
296
|
|
|
255
297
|
**Example: 8-bit Simulation**
|
|
256
298
|
|
|
@@ -284,10 +326,39 @@ math_engine.load_preset(settings)
|
|
|
284
326
|
math_engine.evaluate("FF + 3")
|
|
285
327
|
# Decimal('258')
|
|
286
328
|
```
|
|
287
|
-
|
|
288
329
|
Input validation ensures safety and prevents mixing incompatible formats in strict modes.
|
|
289
330
|
|
|
290
331
|
---
|
|
332
|
+
## Bitwise & Low-Level Operations
|
|
333
|
+
|
|
334
|
+
Math Engine now includes a rich collection of low-level bit manipulation functions commonly used in systems programming, embedded development, cryptography, and hardware-oriented tools.
|
|
335
|
+
|
|
336
|
+
**Bitwise functions:**
|
|
337
|
+
- `bitand(x, y)` — bitwise AND
|
|
338
|
+
- `bitor(x, y)` — bitwise OR
|
|
339
|
+
- `bitxor(x, y)` — bitwise XOR
|
|
340
|
+
- `bitnot(x)` — bitwise NOT
|
|
341
|
+
|
|
342
|
+
**Bit manipulation utilities:**
|
|
343
|
+
- `setbit(x, n)` — sets bit *n*
|
|
344
|
+
- `clrbit(x, n)` — clears bit *n*
|
|
345
|
+
- `togbit(x, n)` — toggles bit *n*
|
|
346
|
+
- `testbit(x, n)` — returns 1 if bit *n* is set, else 0
|
|
347
|
+
|
|
348
|
+
**Shift operations:**
|
|
349
|
+
- `shl(x, n)` — logical left shift
|
|
350
|
+
- `shr(x, n)` — logical right shift
|
|
351
|
+
|
|
352
|
+
All bitwise functions:
|
|
353
|
+
- respect `word_size` and `signed_mode`
|
|
354
|
+
- support overflow/wrap-around behavior
|
|
355
|
+
- fully support binary, hex, decimal, and octal inputs
|
|
356
|
+
- participate in the AST just like standard operators
|
|
357
|
+
- support underscores in non-decimal literals (`0b1111_0000`)
|
|
358
|
+
|
|
359
|
+
This makes Math Engine behave like a full-featured programmer’s calculator with CPU-like precision control.
|
|
360
|
+
|
|
361
|
+
-----
|
|
291
362
|
|
|
292
363
|
# Settings System
|
|
293
364
|
|
|
@@ -339,16 +410,16 @@ You can also read a single setting:
|
|
|
339
410
|
decimal_places = math_engine.load_one_setting("decimal_places")
|
|
340
411
|
```
|
|
341
412
|
|
|
342
|
-
|
|
413
|
+
-----
|
|
343
414
|
|
|
344
415
|
# Error Handling
|
|
345
416
|
|
|
346
417
|
Every error is a custom exception with:
|
|
347
418
|
|
|
348
|
-
* Human-readable message
|
|
349
|
-
* Machine-readable error code
|
|
350
|
-
* Position (if applicable)
|
|
351
|
-
* The original expression
|
|
419
|
+
* Human-readable message
|
|
420
|
+
* Machine-readable error code
|
|
421
|
+
* Position (if applicable)
|
|
422
|
+
* The original expression
|
|
352
423
|
|
|
353
424
|
Example:
|
|
354
425
|
|
|
@@ -377,17 +448,16 @@ except E.CalculationError as e:
|
|
|
377
448
|
|
|
378
449
|
For a complete list of all error codes and their meanings, please see the **[Error Codes Reference](https://github.com/JanTeske06/math_engine/blob/master/ERRORS.md)**.
|
|
379
450
|
|
|
380
|
-
|
|
381
|
-
---
|
|
451
|
+
-----
|
|
382
452
|
|
|
383
453
|
# Testing and Reliability
|
|
384
454
|
|
|
385
|
-
|
|
455
|
+
math\_engine is designed with testing in mind:
|
|
386
456
|
|
|
387
|
-
* Full error-code consistency
|
|
388
|
-
* Strict syntax rules
|
|
389
|
-
* Unit-test friendly behavior
|
|
390
|
-
* No reliance on Python’s runtime execution
|
|
457
|
+
* Full error-code consistency
|
|
458
|
+
* Strict syntax rules
|
|
459
|
+
* Unit-test friendly behavior
|
|
460
|
+
* No reliance on Python’s runtime execution
|
|
391
461
|
|
|
392
462
|
Example with `pytest`:
|
|
393
463
|
|
|
@@ -404,22 +474,22 @@ def test_division_by_zero_error_code():
|
|
|
404
474
|
|
|
405
475
|
You can also test more advanced behavior (non-decimal, strict modes, bitwise operations, etc.) in the same way.
|
|
406
476
|
|
|
407
|
-
|
|
477
|
+
-----
|
|
408
478
|
|
|
409
479
|
# Performance
|
|
410
480
|
|
|
411
|
-
* No use of Python `eval()`
|
|
412
|
-
* Predictable performance through AST evaluation
|
|
413
|
-
* Optimized tokenization
|
|
414
|
-
* Fast conversion of non-decimal numbers
|
|
481
|
+
* No use of Python `eval()`
|
|
482
|
+
* Predictable performance through AST evaluation
|
|
483
|
+
* Optimized tokenization
|
|
484
|
+
* Fast conversion of non-decimal numbers
|
|
415
485
|
|
|
416
486
|
Future updates focus on:
|
|
417
487
|
|
|
418
|
-
* Expression caching
|
|
419
|
-
* Compiler-like optimizations
|
|
420
|
-
* Faster scientific evaluation
|
|
488
|
+
* Expression caching
|
|
489
|
+
* Compiler-like optimizations
|
|
490
|
+
* Faster scientific evaluation
|
|
421
491
|
|
|
422
|
-
|
|
492
|
+
-----
|
|
423
493
|
|
|
424
494
|
# Use Cases
|
|
425
495
|
|
|
@@ -443,32 +513,38 @@ Rejects arbitrary Python code and ensures controlled evaluation.
|
|
|
443
513
|
|
|
444
514
|
Conversion between hex/bin/decimal is easy and reliable.
|
|
445
515
|
|
|
446
|
-
|
|
516
|
+
-----
|
|
447
517
|
|
|
448
518
|
# Roadmap (Future Versions)
|
|
449
519
|
|
|
450
|
-
* Non-decimal output formatting upgrades
|
|
451
|
-
* Strict type-matching modes
|
|
452
|
-
* Function overloading
|
|
453
|
-
* Memory/register system
|
|
454
|
-
* Speed optimization via caching
|
|
455
|
-
* User-defined functions
|
|
456
|
-
* Expression pre-compilation
|
|
457
|
-
* Better debugging output
|
|
520
|
+
* Non-decimal output formatting upgrades
|
|
521
|
+
* Strict type-matching modes
|
|
522
|
+
* Function overloading
|
|
523
|
+
* Memory/register system
|
|
524
|
+
* Speed optimization via caching
|
|
525
|
+
* User-defined functions
|
|
526
|
+
* Expression pre-compilation
|
|
527
|
+
* Better debugging output
|
|
458
528
|
|
|
459
|
-
|
|
529
|
+
-----
|
|
460
530
|
|
|
461
|
-
#
|
|
531
|
+
# Changelog
|
|
462
532
|
|
|
463
|
-
|
|
533
|
+
See [CHANGELOG.md](https://github.com/JanTeske06/math_engine/blob/master/CHANGELOG.md) for details.
|
|
464
534
|
|
|
465
|
-
|
|
535
|
+
-----
|
|
536
|
+
|
|
537
|
+
# License
|
|
538
|
+
[MIT License](https://github.com/JanTeske06/math_engine/blob/master/LICENSE)
|
|
539
|
+
|
|
540
|
+
-----
|
|
466
541
|
|
|
467
542
|
# Contributing
|
|
468
543
|
|
|
469
544
|
Contributions are welcome.
|
|
470
545
|
Feel free to submit issues or PRs on GitHub:
|
|
471
546
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
547
|
+
[https://github.com/JanTeske06/math\_engine](https://github.com/JanTeske06/math_engine)
|
|
548
|
+
|
|
549
|
+
---
|
|
550
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
# Math Engine 0.
|
|
2
|
+
# Math Engine 0.5.0
|
|
3
3
|
|
|
4
4
|
[](https://pypi.org/project/math-engine/)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -19,7 +19,7 @@ It provides a complete pipeline:
|
|
|
19
19
|
* Scientific functions
|
|
20
20
|
* Strict error codes for reliable debugging and automated testing
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
|
|
24
24
|
This library is ideal for:
|
|
25
25
|
|
|
@@ -48,7 +48,7 @@ This library is ideal for:
|
|
|
48
48
|
* `only_binary`
|
|
49
49
|
* `only_octal`
|
|
50
50
|
|
|
51
|
-
### Non-Decimal Support
|
|
51
|
+
### Non-Decimal Support
|
|
52
52
|
|
|
53
53
|
* Read binary `0b1101`
|
|
54
54
|
* Read octal `0o755`
|
|
@@ -65,7 +65,49 @@ This library is ideal for:
|
|
|
65
65
|
pip install math-engine
|
|
66
66
|
````
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
-----
|
|
69
|
+
|
|
70
|
+
# Command Line Interface (CLI)
|
|
71
|
+
|
|
72
|
+
Math Engine works directly from your terminal\! After installing via pip, you can use the command `math-engine` (or the short alias `calc`).
|
|
73
|
+
|
|
74
|
+
### 1\. Interactive Mode (REPL)
|
|
75
|
+
|
|
76
|
+
Start the shell to calculate, manage variables, and change settings dynamically.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
$ math-engine
|
|
80
|
+
|
|
81
|
+
Math Engine 0.4.0 Interactive Shell
|
|
82
|
+
Type 'help' for commands, 'exit' to leave.
|
|
83
|
+
----------------------------------------
|
|
84
|
+
Examples:
|
|
85
|
+
>>> 3 + 3 * 4
|
|
86
|
+
15
|
|
87
|
+
|
|
88
|
+
>>> hex: 255
|
|
89
|
+
0xff
|
|
90
|
+
|
|
91
|
+
>>> x + 5, x=10 (Inline Variables)
|
|
92
|
+
15
|
|
93
|
+
|
|
94
|
+
>>> set setting word_size 8
|
|
95
|
+
Setting updated: word_size -> 8
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 2\. Direct Calculation
|
|
99
|
+
|
|
100
|
+
You can also pass expressions directly (great for scripting):
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
$ math-engine "3 + 3"
|
|
104
|
+
6
|
|
105
|
+
|
|
106
|
+
$ math-engine "hex: 255"
|
|
107
|
+
0xff
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
-----
|
|
69
111
|
|
|
70
112
|
# Quick Start
|
|
71
113
|
|
|
@@ -109,17 +151,16 @@ math_engine.evaluate("bool: 3+3=6")
|
|
|
109
151
|
```python
|
|
110
152
|
import math_engine
|
|
111
153
|
|
|
112
|
-
reset_settings()
|
|
154
|
+
math_engine.reset_settings()
|
|
113
155
|
```
|
|
114
156
|
|
|
157
|
+
If a requested output type does not match the actual result, `correct_output_format=True` allows math\_engine to fall back to a compatible type instead of raising an error.
|
|
115
158
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
---
|
|
159
|
+
-----
|
|
119
160
|
|
|
120
161
|
# Prefix System (Casting Syntax)
|
|
121
162
|
|
|
122
|
-
|
|
163
|
+
math\_engine supports a powerful prefix-based casting system:
|
|
123
164
|
|
|
124
165
|
| Prefix | Meaning | Example |
|
|
125
166
|
| -------- | ----------- | ---------------------------------- |
|
|
@@ -139,7 +180,7 @@ math_engine.evaluate("hex: 3 + 3")
|
|
|
139
180
|
# '0x6'
|
|
140
181
|
```
|
|
141
182
|
|
|
142
|
-
|
|
183
|
+
-----
|
|
143
184
|
|
|
144
185
|
# Variables
|
|
145
186
|
|
|
@@ -162,7 +203,7 @@ math_engine.evaluate("A + B", A=10, B=5)
|
|
|
162
203
|
|
|
163
204
|
Variables are mapped internally to a safe internal representation and are designed to be simple and predictable.
|
|
164
205
|
|
|
165
|
-
|
|
206
|
+
-----
|
|
166
207
|
|
|
167
208
|
# Scientific Functions
|
|
168
209
|
|
|
@@ -176,7 +217,7 @@ math_engine.evaluate("pi * 2")
|
|
|
176
217
|
|
|
177
218
|
All functions are processed by the internal `ScientificEngine`, honoring your settings (for example, `use_degrees`).
|
|
178
219
|
|
|
179
|
-
|
|
220
|
+
-----
|
|
180
221
|
|
|
181
222
|
# Linear Equation Solver
|
|
182
223
|
|
|
@@ -187,11 +228,11 @@ math_engine.evaluate("x + 3 = 10")
|
|
|
187
228
|
|
|
188
229
|
Invalid or nonlinear equations produce errors with codes like:
|
|
189
230
|
|
|
190
|
-
* 3005 – Non-linear equation
|
|
191
|
-
* 3002 – Multiple variables
|
|
192
|
-
* 3022 – One side empty
|
|
231
|
+
* 3005 – Non-linear equation
|
|
232
|
+
* 3002 – Multiple variables
|
|
233
|
+
* 3022 – One side empty
|
|
193
234
|
|
|
194
|
-
|
|
235
|
+
-----
|
|
195
236
|
|
|
196
237
|
# Non-Decimal Numbers (Binary, Octal, Hex)
|
|
197
238
|
|
|
@@ -205,9 +246,9 @@ math_engine.evaluate("0b1010 * 3")
|
|
|
205
246
|
|
|
206
247
|
Non-decimal parsing respects the setting `allow_non_decimal`. If it is set to `False`, using `0b`, `0o`, or `0x` will raise a conversion error.
|
|
207
248
|
|
|
208
|
-
|
|
249
|
+
-----
|
|
209
250
|
|
|
210
|
-
# Bitwise Operations & Developer Mode (v0.
|
|
251
|
+
# Bitwise Operations & Developer Mode (v0.5.0)
|
|
211
252
|
|
|
212
253
|
Math Engine can act as a **programmer's calculator**. It supports standard operator precedence and bitwise logic.
|
|
213
254
|
|
|
@@ -228,15 +269,15 @@ Math Engine can act as a **programmer's calculator**. It supports standard opera
|
|
|
228
269
|
|
|
229
270
|
You can simulate hardware constraints (like C++ `int8`, `uint16`, etc.) by setting a `word_size`.
|
|
230
271
|
|
|
231
|
-
* **`word_size: 0` (Default):** Python mode (arbitrary precision, no overflow).
|
|
232
|
-
* **`word_size: 8/16/32/64`:** Enforces bit limits. Numbers will wrap around (overflow) accordingly.
|
|
272
|
+
* **`word_size: 0` (Default):** Python mode (arbitrary precision, no overflow).
|
|
273
|
+
* **`word_size: 8/16/32/64`:** Enforces bit limits. Numbers will wrap around (overflow) accordingly.
|
|
233
274
|
|
|
234
275
|
### Signed vs. Unsigned Mode
|
|
235
276
|
|
|
236
277
|
When `word_size > 0`, you can control how values are interpreted via `signed_mode`:
|
|
237
278
|
|
|
238
|
-
* **`True` (Default):** Use **Two's Complement** for negative values.
|
|
239
|
-
* **`False`:** Treat all values as unsigned.
|
|
279
|
+
* **`True` (Default):** Use **Two's Complement** for negative values.
|
|
280
|
+
* **`False`:** Treat all values as unsigned.
|
|
240
281
|
|
|
241
282
|
**Example: 8-bit Simulation**
|
|
242
283
|
|
|
@@ -270,10 +311,39 @@ math_engine.load_preset(settings)
|
|
|
270
311
|
math_engine.evaluate("FF + 3")
|
|
271
312
|
# Decimal('258')
|
|
272
313
|
```
|
|
273
|
-
|
|
274
314
|
Input validation ensures safety and prevents mixing incompatible formats in strict modes.
|
|
275
315
|
|
|
276
316
|
---
|
|
317
|
+
## Bitwise & Low-Level Operations
|
|
318
|
+
|
|
319
|
+
Math Engine now includes a rich collection of low-level bit manipulation functions commonly used in systems programming, embedded development, cryptography, and hardware-oriented tools.
|
|
320
|
+
|
|
321
|
+
**Bitwise functions:**
|
|
322
|
+
- `bitand(x, y)` — bitwise AND
|
|
323
|
+
- `bitor(x, y)` — bitwise OR
|
|
324
|
+
- `bitxor(x, y)` — bitwise XOR
|
|
325
|
+
- `bitnot(x)` — bitwise NOT
|
|
326
|
+
|
|
327
|
+
**Bit manipulation utilities:**
|
|
328
|
+
- `setbit(x, n)` — sets bit *n*
|
|
329
|
+
- `clrbit(x, n)` — clears bit *n*
|
|
330
|
+
- `togbit(x, n)` — toggles bit *n*
|
|
331
|
+
- `testbit(x, n)` — returns 1 if bit *n* is set, else 0
|
|
332
|
+
|
|
333
|
+
**Shift operations:**
|
|
334
|
+
- `shl(x, n)` — logical left shift
|
|
335
|
+
- `shr(x, n)` — logical right shift
|
|
336
|
+
|
|
337
|
+
All bitwise functions:
|
|
338
|
+
- respect `word_size` and `signed_mode`
|
|
339
|
+
- support overflow/wrap-around behavior
|
|
340
|
+
- fully support binary, hex, decimal, and octal inputs
|
|
341
|
+
- participate in the AST just like standard operators
|
|
342
|
+
- support underscores in non-decimal literals (`0b1111_0000`)
|
|
343
|
+
|
|
344
|
+
This makes Math Engine behave like a full-featured programmer’s calculator with CPU-like precision control.
|
|
345
|
+
|
|
346
|
+
-----
|
|
277
347
|
|
|
278
348
|
# Settings System
|
|
279
349
|
|
|
@@ -325,16 +395,16 @@ You can also read a single setting:
|
|
|
325
395
|
decimal_places = math_engine.load_one_setting("decimal_places")
|
|
326
396
|
```
|
|
327
397
|
|
|
328
|
-
|
|
398
|
+
-----
|
|
329
399
|
|
|
330
400
|
# Error Handling
|
|
331
401
|
|
|
332
402
|
Every error is a custom exception with:
|
|
333
403
|
|
|
334
|
-
* Human-readable message
|
|
335
|
-
* Machine-readable error code
|
|
336
|
-
* Position (if applicable)
|
|
337
|
-
* The original expression
|
|
404
|
+
* Human-readable message
|
|
405
|
+
* Machine-readable error code
|
|
406
|
+
* Position (if applicable)
|
|
407
|
+
* The original expression
|
|
338
408
|
|
|
339
409
|
Example:
|
|
340
410
|
|
|
@@ -363,17 +433,16 @@ except E.CalculationError as e:
|
|
|
363
433
|
|
|
364
434
|
For a complete list of all error codes and their meanings, please see the **[Error Codes Reference](https://github.com/JanTeske06/math_engine/blob/master/ERRORS.md)**.
|
|
365
435
|
|
|
366
|
-
|
|
367
|
-
---
|
|
436
|
+
-----
|
|
368
437
|
|
|
369
438
|
# Testing and Reliability
|
|
370
439
|
|
|
371
|
-
|
|
440
|
+
math\_engine is designed with testing in mind:
|
|
372
441
|
|
|
373
|
-
* Full error-code consistency
|
|
374
|
-
* Strict syntax rules
|
|
375
|
-
* Unit-test friendly behavior
|
|
376
|
-
* No reliance on Python’s runtime execution
|
|
442
|
+
* Full error-code consistency
|
|
443
|
+
* Strict syntax rules
|
|
444
|
+
* Unit-test friendly behavior
|
|
445
|
+
* No reliance on Python’s runtime execution
|
|
377
446
|
|
|
378
447
|
Example with `pytest`:
|
|
379
448
|
|
|
@@ -390,22 +459,22 @@ def test_division_by_zero_error_code():
|
|
|
390
459
|
|
|
391
460
|
You can also test more advanced behavior (non-decimal, strict modes, bitwise operations, etc.) in the same way.
|
|
392
461
|
|
|
393
|
-
|
|
462
|
+
-----
|
|
394
463
|
|
|
395
464
|
# Performance
|
|
396
465
|
|
|
397
|
-
* No use of Python `eval()`
|
|
398
|
-
* Predictable performance through AST evaluation
|
|
399
|
-
* Optimized tokenization
|
|
400
|
-
* Fast conversion of non-decimal numbers
|
|
466
|
+
* No use of Python `eval()`
|
|
467
|
+
* Predictable performance through AST evaluation
|
|
468
|
+
* Optimized tokenization
|
|
469
|
+
* Fast conversion of non-decimal numbers
|
|
401
470
|
|
|
402
471
|
Future updates focus on:
|
|
403
472
|
|
|
404
|
-
* Expression caching
|
|
405
|
-
* Compiler-like optimizations
|
|
406
|
-
* Faster scientific evaluation
|
|
473
|
+
* Expression caching
|
|
474
|
+
* Compiler-like optimizations
|
|
475
|
+
* Faster scientific evaluation
|
|
407
476
|
|
|
408
|
-
|
|
477
|
+
-----
|
|
409
478
|
|
|
410
479
|
# Use Cases
|
|
411
480
|
|
|
@@ -429,32 +498,38 @@ Rejects arbitrary Python code and ensures controlled evaluation.
|
|
|
429
498
|
|
|
430
499
|
Conversion between hex/bin/decimal is easy and reliable.
|
|
431
500
|
|
|
432
|
-
|
|
501
|
+
-----
|
|
433
502
|
|
|
434
503
|
# Roadmap (Future Versions)
|
|
435
504
|
|
|
436
|
-
* Non-decimal output formatting upgrades
|
|
437
|
-
* Strict type-matching modes
|
|
438
|
-
* Function overloading
|
|
439
|
-
* Memory/register system
|
|
440
|
-
* Speed optimization via caching
|
|
441
|
-
* User-defined functions
|
|
442
|
-
* Expression pre-compilation
|
|
443
|
-
* Better debugging output
|
|
505
|
+
* Non-decimal output formatting upgrades
|
|
506
|
+
* Strict type-matching modes
|
|
507
|
+
* Function overloading
|
|
508
|
+
* Memory/register system
|
|
509
|
+
* Speed optimization via caching
|
|
510
|
+
* User-defined functions
|
|
511
|
+
* Expression pre-compilation
|
|
512
|
+
* Better debugging output
|
|
444
513
|
|
|
445
|
-
|
|
514
|
+
-----
|
|
446
515
|
|
|
447
|
-
#
|
|
516
|
+
# Changelog
|
|
448
517
|
|
|
449
|
-
|
|
518
|
+
See [CHANGELOG.md](https://github.com/JanTeske06/math_engine/blob/master/CHANGELOG.md) for details.
|
|
450
519
|
|
|
451
|
-
|
|
520
|
+
-----
|
|
521
|
+
|
|
522
|
+
# License
|
|
523
|
+
[MIT License](https://github.com/JanTeske06/math_engine/blob/master/LICENSE)
|
|
524
|
+
|
|
525
|
+
-----
|
|
452
526
|
|
|
453
527
|
# Contributing
|
|
454
528
|
|
|
455
529
|
Contributions are welcome.
|
|
456
530
|
Feel free to submit issues or PRs on GitHub:
|
|
457
531
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
532
|
+
[https://github.com/JanTeske06/math\_engine](https://github.com/JanTeske06/math_engine)
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|