Re: float is constructible from double, C++23's std::float13_t is not

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm not sure I fully understand that quote: double can be converted to
float (even if float has a lower rank) because they are both "standard",
whereas the same doesn't apply to std::float16_t?

On Fri, Mar 24, 2023, 21:22 Jonathan Wakely <jwakely.gcc@xxxxxxxxx> wrote:

>
>
> On Fri, 24 Mar 2023, 17:05 Filippo Bistaffa via Gcc-help, <
> gcc-help@xxxxxxxxxxx> wrote:
>
>> I was playing around with gcc-trunk's support for C++23's std::float13_t
>> and I found out that, while float is constructible from double, as far as
>> I
>> can tell std::float13_t is not.
>> In other words, the following code compiles OK:
>>
>> #include <stdfloat>
>> #include <vector>
>> int main() {
>>     std::vector<double> x(5);
>>     std::vector<float> y(std::begin(x), std::end(x));
>> }
>>
>> whereas the following does not:
>>
>> #include <stdfloat>
>> #include <vector>
>> int main() {
>>     std::vector<double> x(5);
>>     std::vector<std::float16_t> y(std::begin(x), std::end(x));
>> }
>>
>> See this snippet <https://godbolt.org/z/zq7KdhY44>.
>> Am I missing something or is it supposed to be like that?
>>
>
> Yes, this is the correct behaviour. The C++23 standard says:
>
> "A prvalue of floating-point type can be converted to a prvalue of another
> floating-point type with a greater or equal conversion rank ([conv.rank]
> <https://eel.is/c++draft/conv.rank>).
> A prvalue of standard floating-point type can be converted to a prvalue of
> another standard floating-point type."
>
>
>
>



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux