Opened 10 years ago
Last modified 4 years ago
#6893 assigned Bugs
Inaccurate Radians/Degrees conversion
Reported by: | Owned by: | Jürgen Hunold | |
---|---|---|---|
Milestone: | To Be Determined | Component: | units |
Version: | Boost 1.49.0 | Severity: | Problem |
Keywords: | Cc: |
Description
LS,
The conversion from angles in degrees to radians currently uses a conversion factor of 6.28318530718/360. (File: boost\units\base_units\angle\degree.hpp), which equals 0.0174532925199444444...
This is unnecessarily inaccurate (only 14 significant digits are correct) and gives problems in my application - the actual value reads: 0.017453292519943295769236907684886127134428718885417...
Using this value improves conversion accuracy significantly.
Please consider using this more accurate value. Alternatively, the use of boost::math::constants could be considered, making the factor: boost::math::constants::pi<double>()/180.0 which works fine as well.
Attachments (2)
Change History (9)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 8 years ago
There already exist the necessary constants
boost::math::constants::radian
(=180/pi)
and
boost::math::constants::degree
(=pi/180)
comment:4 by , 7 years ago
The constants in boost/match/constants/constants.hpp certainly appear to have the necessary accuracy. I was somewhat surprised to see only 4 d.p. accuracy when using boost::units conversions between rad/grad/deg due to the low precision constants used here while I was writing unit tests to validate the conversions. Updating it to use the math constants would be much appreciated. Do you need a patch providing?
by , 7 years ago
Attachment: | boost-angle-precision.patch added |
---|
Use boost::math pi constant to increase precision
comment:5 by , 7 years ago
I have added a patch which makes the suggested change to use boost::math::constants::pi (actually, two_pi) to improve the precision. I've tested this locally and all my own unit tests continue to pass with the patched headers.
by , 7 years ago
Attachment: | boost-angle-precision2.patch added |
---|
Updated patch; use degree constant directly (not possible for grad--no constant defined)
comment:7 by , 4 years ago
Please at least change the value to a more precise value if there is no agreement on the best way to retrieve the good value or if we don't want to introduce dependencies on other boost header.
Keeping a needlessly inaccurate value for 6 years is clearly the worst possible situation.
Any update on this? I see the same constant is used in boost 1.54. It would be good to not introduce unnecessary and avoidable inaccuracies in such a foundational location.