Technology
The numeric module for Project Forge provides high-precision arithmetic operations for handling arbitrarily large numbers that exceed the limits of standard floating-point types. It implements mantissa-exponent representation for both Go and TypeScript environments.
Overview
This module provides:
- Large Number Support: Handle numbers beyond standard 64-bit floating-point precision
- Cross-Platform: Identical API and behavior in both Go and TypeScript
- Performance Optimized: Pool-based memory management and efficient algorithms
- Comprehensive Operations: Full arithmetic, comparison, and formatting capabilities
- Multiple Formats: Standard, scientific, engineering, and English notation
Key Features
Precision
- Mantissa-exponent representation for arbitrary precision
- Support for numbers beyond IEEE 754 limits
- Consistent behavior across platforms
Operations
- Complete arithmetic operations (add, subtract, multiply, divide, power)
- Comparison operations (equals, greater than, less than)
- Mathematical functions (absolute value, sign, normalization)
- Format conversions (string, scientific notation, engineering notation)
Performance
- Object pooling in TypeScript for memory efficiency
- Zero-allocation utilities where possible
- Optimized for common mathematical operations
Package Structure
Go Implementation
app/util/numeric/- Core Go implementationNumericstruct with mantissa/exponent fields- Arithmetic and comparison operations
- String formatting and parsing
- JSON marshaling/unmarshaling support
TypeScript Implementation
client/src/numeric/- Full-featured TypeScript class- Pool-based memory management
- Complete arithmetic operations
- Multiple formatting options
- Utility functions and constants
Usage Examples
Go
1 | |
TypeScript
1 | |
Core Types
Go Types
Numeric- Main numeric type with mantissa and exponentmantissa- float64 for the significant digitsexponent- int64 for the power of 10
TypeScript Types
Numeric- Main class with pooling supportMantissaExponent- Interface for mantissa/exponent pairsNumericSource- Union type for input sources (string, number, or MantissaExponent)
Configuration
No additional configuration required. The module works out of the box with sensible defaults for precision and formatting.
Source Code
- Repository: https://github.com/kyleu/projectforge/tree/main/module/numeric
- License: CC0 (Public Domain)
- Author: Kyle U (kyle@kyleu.com)
See Also
- Project Forge Documentation - Complete documentation