Numix is built with mathematical precision as a core principle. The application handles financial calculations where accuracy is critical, implementing multiple layers of validation and safe parsing to prevent errors and ensure reliable results.
All mathematical operations in Numix are designed to avoid common floating-point arithmetic errors and provide accurate results for financial calculations.
Numix uses the math_expressions library (version 3.0.0) as its mathematical foundation. This library provides robust expression parsing and evaluation capabilities.
Safe expression evaluation without direct string execution
Protection against malformed input that could cause crashes
Consistent floating-point arithmetic
Professional-grade calculation reliability
Never use direct eval() or string-to-code execution for mathematical expressions in production applications. This can lead to security vulnerabilities and crashes.
The application ensures that discounts don’t exceed the original price:
if (totalFixedDiscount > origPrice) { _errorMessage = "El descuento no puede ser mayor al precio original"; _clearResults(); notifyListeners(); return;}
When applying multiple percentage discounts, Numix correctly applies them sequentially (not additively) to reflect real-world discount stacking:
// Apply first discountdouble saved1 = currentPrice * (primaryDiscount / 100);currentPrice -= saved1;totalSaved += saved1;// Apply second discount to the already-discounted priceif (additionalDiscount > 0) { double saved2 = currentPrice * (additionalDiscount / 100); currentPrice -= saved2; totalSaved += saved2;}
Sequential discount calculation means a 20% discount followed by a 10% discount results in a total 28% discount, not 30%. This reflects how discounts actually work in retail.
The Sales Price Calculator handles two different profit calculation methods:
// Markup: Percentage added on top of cost_profitAmount = cost * (profitPercent / 100);_baseSalePrice = cost + _profitAmount!;
Margin percentage must be less than 100% as it represents a portion of the final sale price. Markup percentage can exceed 100% as it’s added on top of the cost.
When working with Numix code or extending its functionality:
Always use double.tryParse() for user input
Validate ranges before performing calculations
Clear results when validation fails
Use null to represent “no result” instead of zero
Wrap calculations in try-catch blocks when necessary
Test edge cases including negative numbers, extremely large values, and invalid input
The test suite in test/features/ contains comprehensive examples of edge cases and validation scenarios. Review these tests when implementing new calculators.