Skip to content

Allow NaN and Inf to pass through Stack floating-point push/get/isInstance#208

Merged
kunitoki merged 4 commits intomasterfrom
copilot/allow-nan-inf-values-in-stack
Mar 27, 2026
Merged

Allow NaN and Inf to pass through Stack floating-point push/get/isInstance#208
kunitoki merged 4 commits intomasterfrom
copilot/allow-nan-inf-values-in-stack

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

is_floating_point_representable_by() rejected NaN and Inf with FloatingPointDoesntFitIntoLuaNumber — NaN due to IEEE 754 comparisons always returning false, Inf due to exceeding numeric_limits::max(). Since Lua natively supports both, these values should pass through rather than error.

Changes

  • Source/LuaBridge/detail/LuaHelpers.h / Distribution/LuaBridge/LuaBridge.h: Added early-return true for std::isnan/std::isinf in is_floating_point_representable_by(). Dropped constexpr (not valid for these calls in C++17) and added #include <cmath>.

  • Tests/Source/StackTests.cpp: Added FloatNaNAndInfPush, DoubleNaNAndInfPush, LongDoubleNaNAndInfPush covering push, isInstance, and get round-trip for quiet NaN, +Inf, and −Inf.

// Previously returned FloatingPointDoesntFitIntoLuaNumber error
luabridge::push(L, std::numeric_limits<float>::quiet_NaN()); // now ok
luabridge::push(L, std::numeric_limits<float>::infinity());  // now ok

// get() and isInstance() also work correctly after the fix
auto result = luabridge::get<float>(L, -1);
assert(result && std::isnan(*result));

The fix is applied uniformly via is_floating_point_representable_by(), so push, get, and isInstance all benefit for float, double, and long double.


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI changed the title [WIP] Allow NaN and Inf values in Stack<float> for error handling Allow NaN and Inf to pass through Stack floating-point push/get/isInstance Mar 27, 2026
Copilot AI requested a review from kunitoki March 27, 2026 17:52
@kunitoki kunitoki marked this pull request as ready for review March 27, 2026 18:12
Copy link
Copy Markdown
Owner

@kunitoki kunitoki left a comment

Choose a reason for hiding this comment

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

Great work !

@kunitoki kunitoki merged commit ea8061e into master Mar 27, 2026
35 checks passed
@kunitoki kunitoki deleted the copilot/allow-nan-inf-values-in-stack branch March 27, 2026 20:09
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.

Stack<float> rejects NaN and Inf values, preventing proper error handling in application logic

2 participants