A Java library for performing arbitrary-precision integer and floating-point arithmetic without relying on Java's built-in BigInteger or BigDecimal classes.
The project implements core arithmetic operations from first principles using string-based representations and classical arithmetic algorithms. It supports integers of unlimited size and floating-point numbers with up to 30 digits of precision after the decimal point.
- Arbitrary-precision signed integers
- Addition
- Subtraction
- Multiplication
- Division
- Input validation
- Automatic normalization
- Comparison operations
- Immutable-style arithmetic operations
- Arbitrary-precision floating-point numbers
- Addition
- Subtraction
- Multiplication
- Division
- Support for signed operands
- Decimal alignment and normalization
- Up to 30 digits of precision after the decimal point
- Command-line calculator interface
- Comprehensive JUnit 5 test suite
- Maven build system
- Docker support
- Fully object-oriented design
src/
├── main/
│ └── java/
│ └── arbitraryarithmetic/
│ ├── AInteger.java
│ ├── AFloat.java
│ └── MyInfArith.java
│
└── test/
└── java/
└── arbitraryarithmetic/
├── AIntegerTest.java
└── AFloatTest.java
Implements arbitrary-precision integer arithmetic using string-based storage.
Implements arbitrary-precision floating-point arithmetic by converting decimal values into scaled integer representations and reusing the integer arithmetic engine.
Command-line interface for performing arithmetic operations on integers and floating-point numbers.
Performs digit-by-digit addition from right to left while propagating carries.
Time Complexity: O(n)
Performs digit-by-digit subtraction with borrow propagation.
Time Complexity: O(n)
Implements classical long multiplication.
Time Complexity: O(n × m)
Implements long division and generates decimal expansions up to 30 digits after the decimal point.
Time Complexity: O(n × m)
All inputs are converted to a canonical representation before storage.
Examples:
000123 -> 123
-00045 -> -45
0000 -> 0
-0000 -> 0
001.23000 -> 1.23
-000.5000 -> -0.5
This guarantees consistent internal storage and comparison.
- Java 17+
- Maven 3.8+
mvn clean testmvn clean packageAddition:
java -cp target/classes arbitraryarithmetic.MyInfArith int add 123456789 987654321Output:
1111111110
Subtraction:
java -cp target/classes arbitraryarithmetic.MyInfArith int sub 1000 250Output:
750
Multiplication:
java -cp target/classes arbitraryarithmetic.MyInfArith int mul 12345 67890Output:
838102050
Division:
java -cp target/classes arbitraryarithmetic.MyInfArith int div 1000 3Output:
333
Addition:
java -cp target/classes arbitraryarithmetic.MyInfArith float add 1.25 2.75Output:
4.0
Subtraction:
java -cp target/classes arbitraryarithmetic.MyInfArith float sub 1.25 2.75Output:
-1.5
Multiplication:
java -cp target/classes arbitraryarithmetic.MyInfArith float mul 0.05 -0.1Output:
-0.005
Division:
java -cp target/classes arbitraryarithmetic.MyInfArith float div 5.5 2Output:
2.75
The project includes a comprehensive JUnit 5 test suite covering:
- Constructors
- Parsing
- Input validation
- Normalization
- Positive and negative operands
- Zero handling
- Large numbers
- Decimal arithmetic
- Division by zero
- Edge cases
Current test status:
68 Tests Passed
0 Failures
0 Errors
Run tests using:
mvn testBuild Docker image:
docker build -t arbitrary-precision-arithmetic .Run container:
docker run arbitrary-precision-arithmetic int add 123 456- Multiplication uses classical long multiplication rather than Karatsuba multiplication.
- Floating-point division is limited to 30 digits after the decimal point.
- Scientific notation is not currently supported.
- Karatsuba multiplication
- Fast exponentiation
- Modulo operation
- Scientific notation support
- Arbitrary configurable decimal precision
- Performance benchmarking suite
- Java 17
- Maven
- JUnit 5
- Docker
Atul Boyal
Indian Institute of Technology Hyderabad (IIT Hyderabad)