boostorg / multiprecision

Boost.Multiprecision
Boost Software License 1.0
194 stars 111 forks source link

Is boost::multiprecision::float128 a trivial type? #635

Closed nmnobre closed 1 month ago

nmnobre commented 1 month ago

Hi,

Could you please post the code you used to generate the following?

https://github.com/boostorg/multiprecision/blob/0f6a276756e2fb3b9226000a3b24f788787e2474/example/float128_snips.cpp#L50-L90

For some reason, on my machine, std::is_trivial<float128>::value is false?

Thank you, Nuno

ckormanyos commented 1 month ago

on my machine, std::is_trivial<float128>::value is false?

And I believe on every other machine. This is a software type with a wrapper and it is not trivial.

I hope I got that right, as @jzmaddock can correct me if I'm wrong.

nmnobre commented 1 month ago

Agreed. But the output I quoted clearly states std::is_trivial<> = true?

mborland commented 1 month ago

boost::multiprecision::float128 should be a trivial type since it's just a wrapper over __float128, but godbolt confirms for a range of library versions and compilers it is not: https://godbolt.org/z/PPxa5K5nP. Since it shows type name of float128_t in the above snip that may be from __float128 rather than boost::multiprecision::float128.

nmnobre commented 1 month ago

That's exactly my experience as well, thus why I asked for the actual code. :)

mborland commented 1 month ago

That's exactly my experience as well, thus why I asked for the actual code. :)

I doubt the code still exists since it's not in the repo. The comment in question was added here: https://github.com/boostorg/multiprecision/commit/0fe173730d5e74a376a9e1f080e3a0d801e7bd11, but unfortunately the author of that commit passed a few years ago. I tried Godbolt with the configuration specified in the comment, and it did not show boost::multiprecision::float128 as trivial then either: https://godbolt.org/z/qddTnq8qz

nmnobre commented 1 month ago

Oh, I just noticed is_fundamental is also marked true... I think you might be right, that output isn't representative of boost's wrapper.

nmnobre commented 1 month ago

The copy constructor here is non-trivial, so I think that's the end of that:

https://github.com/boostorg/multiprecision/blob/0f6a276756e2fb3b9226000a3b24f788787e2474/include/boost/multiprecision/number.hpp#L54

jzmaddock commented 1 month ago

I think that output came from something else entirely - we should remove or update it.

I can't help wondering if we could make the type trivial though, it probably should be.