Closed Eren121 closed 2 years ago
Hi @Eren121, I was about to write how m_value
was left default-initialized on purpose. The idea being that, like the float types that it replaces, default initialization means it has indeterminate value. This can have performance benefits when allocating large amounts of them and allows for a more natural replacement of floats with fpm::fixed
.
However, in trying to prove my point with Godbolt, I learned that it doesn't work this way and that you're correct: default initializing an object (whether by itself or e.g. in a default-initializes std::array
) with a defaulted default constructor still default initializes its members. But value initialization with a defaulted default constructor value-initializes its members, whereas value initialization with a user provided default constructor default-initializes it.
So thank you for this improvement!
Currently, doing
fixed_16_16 f {};
does not initializef.m_value
. The expected behaviour is to do zero-initialization, likeint i{}
initializesi
to0
. The simple fix is to mark the constructor as default, which is good anyway.Moreover, it can't be used in
constexpr
expressions:Also some of the operators like
+=
are not marked constexpr but that's another issue.