boost units and single-precision floats

Carel Combrink via Boost-users <[email protected]>
Newsgroups gmane.comp.lib.boost.user
Message-ID <CAAxNqao778ri8Yk2Rt8ceOnGHB_Ee1dT2RUrL++AXDNJsJiumQ@mail.gmail.com>
Hi,

I have aliases for radians and degrees that use float as the storage type.

When I convert between these two units I see the assembly promote
the values to doubles and then back to floats.
How can I make sure that all operations and conversions stay in floats?

PS: I would not be surprised if I have defined my aliases or/and my
conversion functions incorrectly.

My Code:
===
using radians_f = boost::units::quantity<boost::units::si::plane_angle,
float>;
using degrees_f = boost::units::quantity<boost::units::degree::plane_angle,
float>;

degrees_f to_degrees(const radians_f& angle) { return
static_cast<degrees_f>(angle); }
radians_f to_radians(const degrees_f& angle) { return
static_cast<radians_f>(angle); }
===

From compiler explorer I see the following assembly instructions:
https://godbolt.org/z/Gnjr54dn6
cvtss2sd - Converts a single-precision floating-point value in the
“convert-from” source operand to a double-precision floating-point value in
the destination operand.
mulsd - Multiplies the low double-precision floating-point value in the
second source operand by the low double-precision floating-point value in
the first source operand.
cvtsd2ss - Converts a double-precision floating-point value in the
“convert-from” source operand to a single-precision floating-point value

Any help will be appreciated.

Regards,
Carel

_______________________________________________
Boost-users mailing list
[email protected]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.