From 2a41fed8954a0d27f840f040ce3963481ca20db8 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 28 Sep 2025 16:40:36 +0100 Subject: [PATCH 1/2] Fix generation of f32 NAN, INFINITY, and NEG_INFINITY Signed-off-by: Nico Burns --- bindgen-tests/tests/expectations/tests/infinite-macro.rs | 4 ++-- bindgen/codegen/helpers.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/infinite-macro.rs b/bindgen-tests/tests/expectations/tests/infinite-macro.rs index f19879fb17..63b70a1715 100644 --- a/bindgen-tests/tests/expectations/tests/infinite-macro.rs +++ b/bindgen-tests/tests/expectations/tests/infinite-macro.rs @@ -1,3 +1,3 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub const INFINITY: f64 = f64::INFINITY; -pub const NAN: f64 = f64::NAN; +pub const INFINITY: f64 = f64::INFINITY as _; +pub const NAN: f64 = f64::NAN as _; diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 49928cce3a..9b86ba47b0 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -320,14 +320,14 @@ pub(crate) mod ast_ty { } if f.is_nan() { - return Ok(quote! { f64::NAN }); + return Ok(quote! { f64::NAN as _ }); } if f.is_infinite() { let tokens = if f.is_sign_positive() { - quote! { f64::INFINITY } + quote! { f64::INFINITY as _ } } else { - quote! { f64::NEG_INFINITY } + quote! { f64::NEG_INFINITY as _ } }; return Ok(tokens); } From bd1da850e5201fc2cad24d903088150c9d6edaa7 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Thu, 2 Oct 2025 01:04:35 +0100 Subject: [PATCH 2/2] Add tests for f32 literals --- bindgen-tests/tests/expectations/tests/infinite-macro.rs | 4 ++++ bindgen-tests/tests/headers/infinite-macro.h | 2 -- bindgen-tests/tests/headers/infinite-macro.hpp | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) delete mode 100644 bindgen-tests/tests/headers/infinite-macro.h create mode 100644 bindgen-tests/tests/headers/infinite-macro.hpp diff --git a/bindgen-tests/tests/expectations/tests/infinite-macro.rs b/bindgen-tests/tests/expectations/tests/infinite-macro.rs index 63b70a1715..cf2b32f0ed 100644 --- a/bindgen-tests/tests/expectations/tests/infinite-macro.rs +++ b/bindgen-tests/tests/expectations/tests/infinite-macro.rs @@ -1,3 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const INFINITY: f64 = f64::INFINITY as _; +pub const NEG_INFINITY: f64 = f64::NEG_INFINITY as _; pub const NAN: f64 = f64::NAN as _; +pub const F32_INFINITY: f32 = f64::INFINITY as _; +pub const F32_NEG_INFINITY: f32 = f64::NEG_INFINITY as _; +pub const F32_NAN: f32 = f64::NAN as _; diff --git a/bindgen-tests/tests/headers/infinite-macro.h b/bindgen-tests/tests/headers/infinite-macro.h deleted file mode 100644 index ab352c5785..0000000000 --- a/bindgen-tests/tests/headers/infinite-macro.h +++ /dev/null @@ -1,2 +0,0 @@ -#define INFINITY (1.0f/0.0f) -#define NAN (0.0f/0.0f) diff --git a/bindgen-tests/tests/headers/infinite-macro.hpp b/bindgen-tests/tests/headers/infinite-macro.hpp new file mode 100644 index 0000000000..32c8b61911 --- /dev/null +++ b/bindgen-tests/tests/headers/infinite-macro.hpp @@ -0,0 +1,7 @@ +#define INFINITY (1.0f/0.0f) +#define NEG_INFINITY (-1.0f/0.0f) +#define NAN (0.0f/0.0f) + +static const float F32_INFINITY = 1.0f / 0.0f; +static const float F32_NEG_INFINITY = -1.0f / 0.0f; +static const float F32_NAN = 0.0f / 0.0f;