MCPcopy Index your code
hub / github.com/algorithmicsuperintelligence/optillm / normalize_number

Function normalize_number

scripts/eval_math500_benchmark.py:80–106  ·  view source on GitHub ↗

Helper function to normalize number representation.

(num_str: str)

Source from the content-addressed store, hash-verified

78 return None
79
80def 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
108def numerically_equal(str1: str, str2: str) -> bool:
109 """Compare if two numeric strings represent the same value."""

Callers 2

normalize_answerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected