![]() |
Boost Users : |
From: Carel Combrink (carel.combrink_at_[hidden])
Date: 2021-11-19 13:42:33
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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net