Skip to content

[Bug fix] fix#75804

Closed
youge325 wants to merge 1 commit intoPaddlePaddle:developfrom
youge325:bfloat16
Closed

[Bug fix] fix#75804
youge325 wants to merge 1 commit intoPaddlePaddle:developfrom
youge325:bfloat16

Conversation

@youge325
Copy link
Copy Markdown
Contributor

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

更新把 bfloat16.h 中 isinf 的判定从 (a.x & 0x7F80) == 0x7F80 改成 (a.x & 0x7FFF) == 0x7F80,意义在于:

  • 旧实现只屏蔽掉最高位的符号位,同时也在掩码里清除了 7 位尾数。当遇到 NaN(指数全 1、尾数非 0)时 (a.x & 0x7F80) 仍然等于 0x7F80,误把 NaN 判断成 Inf。
  • 新实现在保留尾数位的情况下再比较,当尾数非零时与 0x7F80 不相等,因此能正确地区分 NaN 与 Inf。这让 isinf 只在尾数为 0 的 ±∞ 上返回 true,不会再误报 NaN。

这个改动修复了 bfloat16 类型上 isinf 对 NaN 的误判,提高了数值检查的准确性。

更新把 bfloat16.h 中 `isinf` 的判定从 `(a.x & 0x7F80) == 0x7F80` 改成 `(a.x & 0x7FFF) == 0x7F80`,意义在于:

- 旧实现只屏蔽掉最高位的符号位,同时也在掩码里清除了 7 位尾数。当遇到 NaN(指数全 1、尾数非 0)时 `(a.x & 0x7F80)` 仍然等于 `0x7F80`,误把 NaN 判断成 Inf。
- 新实现在保留尾数位的情况下再比较,当尾数非零时与 `0x7F80` 不相等,因此能正确地区分 NaN 与 Inf。这让 `isinf` 只在尾数为 0 的 ±∞ 上返回 true,不会再误报 NaN。

这个改动修复了 bfloat16 类型上 `isinf` 对 NaN 的误判,提高了数值检查的准确性。
@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented Oct 13, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot Bot added the contributor External developers label Oct 13, 2025
@youge325 youge325 closed this Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant