🧮 DeepMath v2.0
High-Precision Large Number Arithmetic Library for Arduino
DeepMath is a lightweight and efficient Arduino library designed to perform precise mathematical operations on large numbers and decimals. It bypasses the 6-7 digit precision limit of standard float and double types by using optimized integer-based logic.
The previous version (v1.x) of this library is now deprecated. It contained critical bugs that could lead to incorrect results or system instability. Version 2.0 is a complete rewrite that solves these issues.
Major Bug Fixes in v2.0:
- Division Precision: v1.x used float for division, causing rounding errors. v2.0 uses pure integer scaling for 100% accuracy.
- Memory Stability: Removed excessive String usage that caused Heap Fragmentation and crashes on Uno/Nano. v2.0 uses memory-efficient pointers and C-strings.
- Logic Errors: Fixed a bug where 18+ digit numbers would incorrectly repeat digits in LtoS.
- Infinite Loops: Removed dangerous loop conditions that could hang the microcontroller.
- Negative Support: Fully implemented sign handling for all arithmetic operations.
✨ Features
- ✅ Zero Precision Loss: Performs math without floating-point rounding errors.
- ✅ Large Number Support: Handles up to 18-19 digits (using long long).
- ✅ Full Arithmetic: Addition (+), Subtraction (-), Multiplication (*), and Division (/).
- ✅ Memory Optimized: Specifically designed for low-RAM boards like Arduino Uno, Nano, and Pro Mini.
- ✅ Adjustable Division: Specify exactly how many decimal places you need in the result.
📥 Installation
- Download this repository as a .zip file.
- In your Arduino IDE, go to Sketch -> Include Library -> Add .ZIP Library...
- Select the downloaded file.
- Restart your IDE.
🚀 Quick Start
#include <DeepMath.h>
DeepMath math;
void setup() { Serial.begin(9600);
// Example 1: Precise Addition // Result: 123456789.11 Serial.println(math.CALC("123456789.01", '+', "0.10"));
// Example 2: High Precision Division // Getting 10 decimal places for 10/3 Serial.println(math.CALC("10", '/', "3", 10)); // Output: 3.3333333333
// Example 3: Negative Arithmetic Serial.println(math.CALC("5.50", '-', "10.00")); // Output: -4.50 }
void loop() {}
🛠 API Reference
| Function | Parameters | Description |
|---|---|---|
CALC |
String a, char op, String c, int dec |
Performs a (op) c. dec sets decimal places for division. |
LtoS |
long long digit |
Converts a large integer to a String. |
StoL |
const char* s |
Converts a numeric string to a long long. |
AnalyseStr |
const char* s, char mode |
'F' for decimal count, '0' for value without dot. |
- Digit Limit: Maximum of 18-19 digits (standard 64-bit long long limit).
- Functions: Currently supports basic arithmetic only (+, -, *, /). Advanced functions like pow(), sqrt(), or sin() are not included.
📝 ചുരുക്കത്തിൽ (Malayalam Summary)
DeepMath v2.0 എന്നത് ആർഡുനോയിൽ വലിയ സംഖ്യകളും പോയിന്റുള്ള സംഖ്യകളും കൃത്യതയോടെ കണക്കുകൂട്ടാൻ സഹായിക്കുന്ന ഒരു ലൈബ്രറിയാണ്.
v2.0-ലെ മാറ്റങ്ങൾ:
- കൃത്യത: പഴയ വേർഷനിലെ (v1.x) തെറ്റായ ഉത്തരങ്ങൾ നൽകുന്ന രീതി മാറ്റി, 100% കൃത്യത ഉറപ്പുവരുത്തി.
- സ്ഥിരത: ആർഡുനോ ഹാങ്ങ് ആകാൻ കാരണമായിരുന്ന മെമ്മറി പ്രശ്നങ്ങൾ പരിഹരിച്ചു.
- നെഗറ്റീവ് സംഖ്യകൾ: നെഗറ്റീവ് വാല്യൂസ് ഇപ്പോൾ കൃത്യമായി കണക്കുകൂട്ടാം.
- ഹരണക്രിയ: ഹരിക്കുമ്പോൾ പോയിന്റിന് ശേഷം എത്ര അക്കം വേണമെന്ന് നിങ്ങൾക്ക് തീരുമാനിക്കാം.
പഴയ വേർഷൻ ഉപയോഗിക്കുന്നവർ അത് ഒഴിവാക്കി നിർബന്ധമായും ഈ v2.0 വേർഷൻ ഉപയോഗിക്കുക.
👤 Author
Hafiz Amanudeen Pallimukku DeepMath Project
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.