Helper function to normalize number representation.
(num_str: str)
| 78 | return None |
| 79 | |
| 80 | def normalize_number(num_str: str) -> str: |
| 81 | """Helper function to normalize number representation.""" |
| 82 | try: |
| 83 | # Remove commas, currency symbols, units, and whitespace |
| 84 | cleaned = re.sub(r'[,\$\\]|\s*(?:cm|m|kg|ft|in|lb|oz|ml|L)$|\s*\\text{[^}]+}', '', num_str).strip() |
| 85 | |
| 86 | # Handle leading decimal point |
| 87 | if cleaned.startswith('.'): |
| 88 | cleaned = '0' + cleaned |
| 89 | |
| 90 | # Convert to float |
| 91 | num = float(cleaned) |
| 92 | |
| 93 | # For small decimals, preserve exact representation |
| 94 | if abs(num) < 1 and '.' in cleaned: |
| 95 | # Count original decimal places |
| 96 | decimal_places = len(cleaned.split('.')[1]) |
| 97 | format_str = f"{{:.{decimal_places}f}}" |
| 98 | result = format_str.format(num) |
| 99 | else: |
| 100 | result = str(num) |
| 101 | |
| 102 | logger.debug(f"Normalized number result: {repr(result)}") |
| 103 | return result |
| 104 | except Exception as e: |
| 105 | logger.debug(f"Failed to normalize number: {str(e)}") |
| 106 | return num_str |
| 107 | |
| 108 | def numerically_equal(str1: str, str2: str) -> bool: |
| 109 | """Compare if two numeric strings represent the same value.""" |
no outgoing calls
no test coverage detected