Skip to content

Handle signed zero and non-finite f32 constants - #628

Merged
antocuni merged 1 commit into
spylang:mainfrom
filiplajszczak:f32_special_values
Jul 19, 2026
Merged

Handle signed zero and non-finite f32 constants#628
antocuni merged 1 commit into
spylang:mainfrom
filiplajszczak:f32_special_values

Conversation

@filiplajszczak

Copy link
Copy Markdown
Contributor

The interpreter's IEEE-754 division fallback selected infinity from the numerator sign alone, so division by negative zero returned the wrong sign. Combine both operand signs with copysign while retaining NaN for zero divided by zero.

Redshift can fold f32 overflow into infinity. The C writer previously appended an f suffix to Python's spelling and emitted invalid identifiers such as inff and nanf; emit the C99 INFINITY and NAN macros instead.

The signed-zero regression constructs -0.0 inside SPy, so it tests signed-zero behavior independently of Python-to-SPy argument conversion. The constant-emission regression overflows the largest finite f32 deliberately, ensuring the C writer receives a folded non-finite constant instead of a runtime division call.

It was possible thanks to the help of gpt-5.6-sol.

The interpreter's IEEE-754 division fallback selected infinity from the numerator sign alone, so division by negative zero returned the wrong sign. Combine both operand signs with copysign while retaining NaN for zero divided by zero.

Redshift can fold f32 overflow into infinity. The C writer previously appended an f suffix to Python's spelling and emitted invalid identifiers such as inff and nanf; emit the C99 INFINITY and NAN macros instead.

The signed-zero regression constructs -0.0 inside SPy, so it tests signed-zero behavior independently of Python-to-SPy argument conversion. The constant-emission regression overflows the largest finite f32 deliberately, ensuring the C writer receives a folded non-finite constant instead of a runtime division call.

@antocuni antocuni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Will merge as soon as tests turn green

@antocuni
antocuni merged commit 9652de1 into spylang:main Jul 19, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants