Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #84372
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Newsgroups | comp.lang.c++, comp.lang.c, de.comp.lang.c |
| Subject | Re: Fast trunc() algorithm |
| Date | 2022-05-30 06:22 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <t71nqf$6p4$1@gioia.aioe.org> (permalink) |
| References | <t6va0v$eno$1@dont-email.me> <t70p0f$a8$1@dont-email.me> |
Cross-posted to 3 groups.
In comp.lang.c++ Christian Gollwitzer <auriocus@gmx.de> wrote: > Am 29.05.22 um 10:14 schrieb Bonita Montero: >> >> memcpy() is the only valid way to have writeable aliasing in C++. >> memcpy() is normally an intrinsic function and in the above code >> the memcpy()s between integral and floating point types are just >> moves between general purpose and FPU-registers. > > How about reinterpret_cast<> ? Doing type punning, ie. interpreting the bit representation of some type as a value of an incompatible type, by reinterpret-casting a pointer to that value, or by using a union, is technically speaking UB in C++ (but allowed in C, I think since C11 or the like), even though in practice it does work (for the same reason it does in C). The only "official" way of doing it (prior to C++20) was to use std::memcpy() (and hope that the compiler will optimize it into equivalent code as using a union). C++20 added an official way of doing type punning: std::bit_cast.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-05-29 10:14 +0200
Re: Fast trunc() algorithm Muttley@dastardlyhq.com - 2022-05-29 08:21 +0000
Re: Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-05-29 10:29 +0200
Re: Fast trunc() algorithm Freethinker <freethinker@mymail.com> - 2022-05-29 15:20 +0200
Re: Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-05-29 15:27 +0200
Re: Fast trunc() algorithm Freethinker <freethinker@mymail.com> - 2022-05-29 15:37 +0200
Re: Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-05-29 15:46 +0200
Re: Fast trunc() algorithm John McCue <jmccue@magnetar.hsd1.ma.comcast.net> - 2022-05-29 21:32 +0000
Re: Fast trunc() algorithm Christian Gollwitzer <auriocus@gmx.de> - 2022-05-29 23:36 +0200
Re: Fast trunc() algorithm Juha Nieminen <nospam@thanks.invalid> - 2022-05-30 06:22 +0000
Re: Fast trunc() algorithm David Brown <david.brown@hesbynett.no> - 2022-05-30 08:59 +0200
Re: Fast trunc() algorithm muttley@dastardlyhq.com - 2022-05-30 07:52 +0000
Re: Fast trunc() algorithm Paavo Helde <eesnimi@osa.pri.ee> - 2022-05-30 11:58 +0300
Re: Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-05-30 11:32 +0200
Re: Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-05-30 11:34 +0200
Re: Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-05-31 05:41 +0200
Re: Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-06-01 18:07 +0200
Re: Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-06-01 18:09 +0200
Re: Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-06-02 04:43 +0200
Re: Fast trunc() algorithm jak <nospam@please.ty> - 2022-06-02 07:44 +0200
Re: Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-06-02 08:14 +0200
Re: Fast trunc() algorithm jak <nospam@please.ty> - 2022-06-02 11:14 +0200
Re: Fast trunc() algorithm Bonita Montero <Bonita.Montero@gmail.com> - 2022-06-02 12:48 +0200
csiph-web