public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* float is constructible from double, C++23's std::float13_t is not
@ 2023-03-24 17:04 Filippo Bistaffa
  2023-03-24 20:22 ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Filippo Bistaffa @ 2023-03-24 17:04 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

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?

Thanks,
Filippo Bistaffa

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: float is constructible from double, C++23's std::float13_t is not
  2023-03-24 17:04 float is constructible from double, C++23's std::float13_t is not Filippo Bistaffa
@ 2023-03-24 20:22 ` Jonathan Wakely
  2023-03-25 11:29   ` Filippo Bistaffa
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2023-03-24 20:22 UTC (permalink / raw)
  To: Filippo Bistaffa; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1155 bytes --]

On Fri, 24 Mar 2023, 17:05 Filippo Bistaffa via Gcc-help, <
gcc-help@gcc.gnu.org> 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."

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: float is constructible from double, C++23's std::float13_t is not
  2023-03-24 20:22 ` Jonathan Wakely
@ 2023-03-25 11:29   ` Filippo Bistaffa
  2023-03-25 11:58     ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Filippo Bistaffa @ 2023-03-25 11:29 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1484 bytes --]

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@gmail.com> wrote:

>
>
> On Fri, 24 Mar 2023, 17:05 Filippo Bistaffa via Gcc-help, <
> gcc-help@gcc.gnu.org> 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."
>
>
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: float is constructible from double, C++23's std::float13_t is not
  2023-03-25 11:29   ` Filippo Bistaffa
@ 2023-03-25 11:58     ` Jonathan Wakely
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2023-03-25 11:58 UTC (permalink / raw)
  To: Filippo Bistaffa; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1748 bytes --]

On Sat, 25 Mar 2023, 11:29 Filippo Bistaffa, <filippo.bistaffa@gmail.com>
wrote:

> 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?
>

Correct. float16_t is an extended floating-point type.

https://en.cppreference.com/w/cpp/language/types#Floating-point_types


> On Fri, Mar 24, 2023, 21:22 Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>
>>
>>
>> On Fri, 24 Mar 2023, 17:05 Filippo Bistaffa via Gcc-help, <
>> gcc-help@gcc.gnu.org> 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."
>>
>>
>>
>>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-25 11:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24 17:04 float is constructible from double, C++23's std::float13_t is not Filippo Bistaffa
2023-03-24 20:22 ` Jonathan Wakely
2023-03-25 11:29   ` Filippo Bistaffa
2023-03-25 11:58     ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).