How are floats as non type template parameters treated when it comes to template specialization

Viewed 102

Consider following program:

#include <iostream>
#include <limits>

template<float f>
void fun(){
    std::cout << "val: " << f << "\n";
}

template<>
void fun<std::numeric_limits<float>::signaling_NaN()>(){
    std::cout << "sn\n";
}

int main() {
    static_assert(std::numeric_limits<float>::signaling_NaN()!=std::numeric_limits<float>::signaling_NaN());
    fun<std::numeric_limits<float>::signaling_NaN()>();
    fun<std::numeric_limits<float>::quiet_NaN()>();
}

It prints out:

sn
val: nan

So this makes me think that compiler does bitwise comparison of floats when it comes to template specialization consideration(see static_assert). Is this correct?

I tried reading the 13.4.3 Template non-type arguments but it does not seem specified there, but I have really hard time reading the standard so I may be missing something obvious.

0 Answers
Related