Skip to content

Commit f3e47dc

Browse files
rustyconoverclaude
andcommitted
Promote float32→float64 in _promote_for_addition for overflow safety
float32 addition can overflow just like integer addition. Promote float16/float32 to float64, matching the existing integer promotion pattern (int32→int64, etc.). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3b366ad commit f3e47dc

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

vgi/examples/scalar.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ def _promote_for_addition(dtype: pa.DataType) -> pa.DataType:
7575
Adding two values of the same type can overflow, so we promote integers
7676
to the next larger size. For example, int32 + int32 -> int64.
7777
"""
78-
if pa.types.is_floating(dtype) or pa.types.is_temporal(dtype):
78+
if pa.types.is_temporal(dtype):
79+
return dtype
80+
if pa.types.is_floating(dtype):
81+
# Promote float32 -> float64 to reduce overflow risk
82+
if dtype == pa.float16() or dtype == pa.float32():
83+
return pa.float64()
7984
return dtype
8085
if pa.types.is_integer(dtype):
8186
# Promote to a larger integer type since a + b can overflow

0 commit comments

Comments
 (0)