|
| 1 | +# DeepMath |
| 2 | +DeepMath is a lightweight Arduino library by "Hfiz Amanudeen pallimukku"for performing high-precision decimal and large number arithmetic operations without using floating point types (float or double) or external libraries like sprintf, string, or stringstream. |
| 3 | + |
| 4 | +This library is designed for use in memory-limited microcontrollers (such as ESP32-Wroom,ATmega328, ESP32-CAM, etc.) where standard math functions are not reliable for large or precise decimal operations. |
| 5 | + |
| 6 | +📘 Usage |
| 7 | +cpp |
| 8 | + |
| 9 | +#include <DeepMath.h> |
| 10 | + |
| 11 | +void setup() { |
| 12 | + Serial.begin(9600); |
| 13 | + |
| 14 | + long long num = 1234567890123456789LL; |
| 15 | + |
| 16 | + // Convert large number to string |
| 17 | + String re |
| 18 | +--- |
| 19 | + |
| 20 | +## ✨ Features |
| 21 | + |
| 22 | +- Pure logic-based implementation |
| 23 | +- Works with very large integers (`long long`, `unsigned long long`) |
| 24 | +- Supports: |
| 25 | + - Integer to String conversion (up to 20 digits) |
| 26 | + - Decimal point insertion without float |
| 27 | + - Manual power, division, and addition logic |
| 28 | +- Minimal dependencies (`Arduino.h` and `math.h` only) |
| 29 | +- No dynamic memory allocation (`malloc`, `new`, etc.) |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## 🔧 Installation |
| 34 | + |
| 35 | +### Method 1: Manually |
| 36 | + |
| 37 | +1. Download or clone this repository: |
| 38 | +2. Move the folder into your Arduino libraries directory: |
| 39 | + |
| 40 | +### Method 2: Zip Import |
| 41 | + |
| 42 | +1. Go to Arduino IDE → Sketch → Include Library → Add .ZIP Library. |
| 43 | +2. Select the zipped DeepMath folder. |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## 📘 Usage |
| 48 | + |
| 49 | +```cpp |
| 50 | +#include <DeepMath.h> |
| 51 | +DeepMath math; |
| 52 | +void setup() { |
| 53 | + Serial.begin(9600); |
| 54 | + |
| 55 | + long long num = 1234567890123456789LL; |
| 56 | + |
| 57 | + // Convert large number to string |
| 58 | + String result = math.LtoS(num); |
| 59 | + Serial.println(result); |
| 60 | + |
| 61 | + // Convert string to large number |
| 62 | + Serial.println(math.StoL(result)); |
| 63 | + |
| 64 | + // Get total number of digits (including decimals) |
| 65 | + Serial.println(math.AnalyseStr("34.567", 'T')); // Output: 6 |
| 66 | + |
| 67 | + // Remove decimal point and return pure number |
| 68 | + Serial.println(math.AnalyseStr("123.4567", '0')); // Output: 1234567 |
| 69 | + |
| 70 | + // Get number of digits before the decimal point |
| 71 | + Serial.println(math.AnalyseStr("123.4567", 'F')); // Output: 3 |
| 72 | + |
| 73 | + // Get only the integer part (truncate decimal) |
| 74 | + Serial.print("Integer part of 1234.567: "); |
| 75 | + Serial.println(math.AnalyseStr("1234.567", '#')); // Output: 1234 |
| 76 | + |
| 77 | + // Arithmetic operations on large decimal values |
| 78 | + Serial.println(math.CALC("35.74537", '*', "1.223538",0)); // Multiplication |
| 79 | + Serial.println(math.CALC("36.56776878", '/', "12.234567",5)); // Division |
| 80 | + Serial.println(math.CALC("43.23849487", '+', "6.832734",0)); // Addition |
| 81 | + Serial.println(math.CALC("68.323327", '-', "43.2367237",0)); // Subtraction |
| 82 | +} |
| 83 | + |
| 84 | +void loop() { |
| 85 | + // Your code here |
| 86 | +} |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
0 commit comments