Fix CanonNaN template to use correct type for f64 NaN canonicalization#2701
Merged
Merged
Conversation
The CanonNaN<T> template function was hardcoding std::numeric_limits<f32>::quiet_NaN() instead of using the template parameter T. When T is f64, this returns the wrong canonical NaN bit pattern (an f32 quiet NaN implicitly promoted to f64), instead of the correct f64 quiet NaN. Replace f32 with T so that std::numeric_limits<T>::quiet_NaN() is used, returning the correct canonical NaN for both f32 and f64.
sbc100
approved these changes
Feb 25, 2026
sbc100
left a comment
Member
There was a problem hiding this comment.
I wonder why we don't see any test failures because of this?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CanonNaN<T>template function ininterp-math.hhardcodesstd::numeric_limits<f32>::quiet_NaN()instead of using the template parameterT.Tisf64, this returns anf32quiet NaN implicitly promoted tof64, which has a different bit pattern than the correctf64canonical NaN.f32withTso thatstd::numeric_limits<T>::quiet_NaN()produces the correct canonical NaN for bothf32andf64.Test plan
cmake --build build --target wabt-unittestsbuilds successfullyFloatDiv,FloatMin,FloatMaxall correctly usestd::numeric_limits<T>::quiet_NaN())