Skip to content

[SYCL][libdevice] return qNaN for (float/double)sNaN to bfloat16 conversion - #23084

Open
Maetveis wants to merge 1 commit into
intel:syclfrom
Maetveis:libdevice-float-to-bfloat-snan
Open

[SYCL][libdevice] return qNaN for (float/double)sNaN to bfloat16 conversion#23084
Maetveis wants to merge 1 commit into
intel:syclfrom
Maetveis:libdevice-float-to-bfloat-snan

Conversation

@Maetveis

@Maetveis Maetveis commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

#22114 introduced a fix to return NaN for some specific float or double sNaN bit patterns when converting to bfloat16.
Together with that change it also changed the behavior and added a test specifically for the case of converting sNaN to bfloat16. The new behaviour in that PR is to return sNaN for all sNaN inputs.

This is not the correct behaviour, IEEE 754 specifies conversions should signal and then return a quiet NaN. We do not implement raising exceptions in the device library, so we cannot signal, but we should still return a quiet NaN for all sNaN inputs.
The new behaviour matches the host conversion (from glibc/compiler-rt), see this example on compiler explorer: https://godbolt.org/z/E7ezaPxEd (assisted by Claude Opus 5 noreply@anthropic.com).

…ersion

intel#22114 introduced a fix to return
NaN for some specific float or double sNaN bit patterns when converting
to bfloat16.
Together with that change it also changed the behavior and added a test
specifically for the case of converting sNaN to bfloat16. The new
behaviour in that PR is to return sNaN for all sNaN inputs.

This is not the correct behaviour, IEEE 754 specifies conversions should
signal and then return a quiet NaN. We do not implement raising exceptions
in the device library, so we cannot signal, but we should still return
a quiet NaN for all sNaN inputs.
The new behaviour matches the host conversion (from glibc/compiler-rt),
see this example on compiler explorer: https://godbolt.org/z/E7ezaPxEd
(assisted by Claude Opus 5 <noreply@anthropic.com>).
@Maetveis
Maetveis requested a review from a team as a code owner September 2, 2026 09:42
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.

1 participant