MCPcopy Create free account
hub / github.com/apache/fory / _numeric_value

Function _numeric_value

python/pyfory/converter.py:328–350  ·  view source on GitHub ↗
(value, local_type_id: int)

Source from the content-addressed store, hash-verified

326
327
328def _numeric_value(value, local_type_id: int):
329 if type(value) is str:
330 if local_type_id in _FLOAT_TYPE_IDS and value.startswith("-"):
331 decimal_value = _decimal_from_text(value)
332 if decimal_value.is_zero():
333 return _to_float_domain(-0.0, local_type_id)
334 value = _decimal_from_text(value)
335 elif type(value) is bool:
336 value = 1 if value else 0
337 if local_type_id in _INT_RANGES_BY_TYPE_ID:
338 return _int_value(value, local_type_id)
339 if local_type_id in _FLOAT_TYPE_IDS:
340 return _float_value(value, local_type_id)
341 if local_type_id == TypeId.DECIMAL:
342 if type(value) is int:
343 return decimal.Decimal(value)
344 if type(value) is float:
345 if not math.isfinite(value):
346 raise ValueError("non-finite float cannot convert to decimal")
347 return _decimal_from_float_value(value)
348 if isinstance(value, decimal.Decimal):
349 return _canonical_decimal(value)
350 raise ValueError(f"type id {local_type_id} is not a numeric scalar")
351
352
353def compatible_scalar_convert(value, remote_type_id: int, local_type_id: int):

Callers 1

Calls 8

_decimal_from_textFunction · 0.85
_to_float_domainFunction · 0.85
_int_valueFunction · 0.85
_float_valueFunction · 0.85
_canonical_decimalFunction · 0.85
is_zeroMethod · 0.45
DecimalMethod · 0.45

Tested by

no test coverage detected