(value, local_type_id: int)
| 232 | |
| 233 | |
| 234 | def _float_value(value, local_type_id: int) -> float: |
| 235 | if isinstance(value, decimal.Decimal): |
| 236 | value = _canonical_decimal(value) |
| 237 | if value.is_zero(): |
| 238 | return 0.0 |
| 239 | result = _to_float_domain(float(value), local_type_id) |
| 240 | if _decimal_from_float_value(result) != value: |
| 241 | raise ValueError("decimal value is not exactly representable by target float") |
| 242 | return result |
| 243 | if type(value) is int: |
| 244 | result = _to_float_domain(float(value), local_type_id) |
| 245 | if not math.isfinite(result) or int(result) != value: |
| 246 | raise ValueError("integer value is not exactly representable by target float") |
| 247 | return result |
| 248 | if type(value) is float: |
| 249 | if math.isnan(value): |
| 250 | raise ValueError("NaN is not convertible across floating types") |
| 251 | result = _to_float_domain(value, local_type_id) |
| 252 | if not _same_float_value(_to_float_domain(result, local_type_id), result): |
| 253 | raise ValueError("target float round-trip failed") |
| 254 | if not _same_float_value(result, value): |
| 255 | raise ValueError("floating value is not exactly representable by target float") |
| 256 | return result |
| 257 | raise ValueError(f"expected numeric value, got {type(value)!r}") |
| 258 | |
| 259 | |
| 260 | def _bool_value(value) -> bool: |
no test coverage detected