DeepMath is a lightweight and dependency-free Arduino library by Hafiz Amanudeen Pallimukku for performing high-precision decimal and large-number arithmetic operations without using float
, double
, or complex string-based libraries like sprintf
, string
, or stringstream
.
Designed especially for memory-constrained microcontrollers like ESP32-WROOM, ESP32-CAM, ATmega328, etc., where native floating point operations are not reliable or precise for large values.
- ✅ Pure logic-based implementation (no floating point math)
- 🔢 Works with very large integers (
long long
,unsigned long long
) - 🔧 Manual implementations of:
- Integer-to-string and string-to-integer conversion
- Decimal point handling
- Power, division, addition logic
- 🪶 Minimal dependencies (
Arduino.h
,math.h
) - 🚫 No dynamic memory (
malloc
,new
, etc.)
- Download or clone this repository.
- Move the folder into your Arduino
libraries
directory.
- Open Arduino IDE → Sketch → Include Library → Add .ZIP Library.
- Select the zipped DeepMath folder.
#include <DeepMath.h>
DeepMath math;
void setup() {
Serial.begin(9600);
long long num = 1234567890123456789LL;
// Convert large number to string
String result = math.LtoS(num);
Serial.println(result);
// Convert string to large number
Serial.println(math.StoL(result));
// Get total number of digits (including decimals)
Serial.println(math.LtoS(math.AnalyseStr("34.567", 'T'))); // Output: 6
// Remove decimal point and return pure number
Serial.println(math.LtoS(math.AnalyseStr("123.4567", '0'))); // Output: 1234567
// Get number of digits before the decimal point
Serial.println(math.LtoS(math.AnalyseStr("123.4567", 'F'))); // Output: 3
// Get only the integer part (truncate decimal)
Serial.print("Integer part of 1234.567: ");
Serial.println(math.LtoS(math.AnalyseStr("1234.567", '#'))); // Output: 1234
// Arithmetic operations on large decimal values
Serial.println(math.CALC("35.74537", '*', "1.223538",0)); // Multiplication
Serial.println(math.CALC("36.56776878", '/', "12.234567",6)); // Division
Serial.println(math.CALC("43.23849487", '+', "6.832734",0)); // Addition
Serial.println(math.CALC("68.323327", '-', "43.2367237",0)); // Subtraction
}
void loop() {
// Your code here
}
void loop() {
// Optional: continuous tasks
}