Hi,
I have a code that uses "double precision" sin/cos/asin/acos/atan/fabs functions.
I get different results when running same code on PC and ESP32 (IDF 4.0).
Is there a compiler/config settings or external lib that I should use to get same results?
Thanks.
Enable double precision trigonometric functions
-
- Posts: 8
- Joined: Tue Oct 06, 2020 12:40 pm
Re: Enable double precision trigonometric functions
Hi alsaleem00,
ESP32 does not support hardware acceleration for double precision floating point arithmetic (double). Instead double is implemented via software hence the behavioral restrictions with regards to float do not apply to double. Note that due to the lack of hardware acceleration, double operations may consume significantly larger amount of CPU time in comparison to float.
It is also possible that this software implementation contains a bug.
Please post the code you used so we can investigate this.
You might also want to consider using float for the hardware acceleration if that's precise enough for your application.
Jan
ESP32 does not support hardware acceleration for double precision floating point arithmetic (double). Instead double is implemented via software hence the behavioral restrictions with regards to float do not apply to double. Note that due to the lack of hardware acceleration, double operations may consume significantly larger amount of CPU time in comparison to float.
It is also possible that this software implementation contains a bug.
Please post the code you used so we can investigate this.
You might also want to consider using float for the hardware acceleration if that's precise enough for your application.
Jan
Re: Enable double precision trigonometric functions
Example code? Results ?
IT Professional, Maker
Santiago, Dominican Republic
Santiago, Dominican Republic
-
- Posts: 75
- Joined: Fri Dec 04, 2020 9:56 pm
Re: Enable double precision trigonometric functions
alsaleem00 wrote: Hi,
I have a code that uses "double precision" sin/cos/asin/acos/atan/fabs functions.
I get different results when running same code on PC and ESP32 (IDF 4.0).
Aren't you just observing a rounding error?
-
- Posts: 8
- Joined: Tue Oct 06, 2020 12:40 pm
Re: Enable double precision trigonometric functions
I changed to float per recommendation. Now both platforms produce same result.
Yes, I experienced slow processing so I opted to go to float.
Thanks for support.
Yes, I experienced slow processing so I opted to go to float.
Thanks for support.
-
- Posts: 1
- Joined: Sun Oct 31, 2021 2:26 am
Re: Enable double precision trigonometric functions
I have a problem in the esp32 IDF floating arithmetic.
The operation is:
Float x, y;
x = -0.141
y = -0.555
Abs(x - y) should be 0.414 but the esp32 is resolving it as 0.696.
Can anyone explain what is happening here. It’s a simple calculation of the absolute value of subtracting two negative float numbers.
The operation is:
Float x, y;
x = -0.141
y = -0.555
Abs(x - y) should be 0.414 but the esp32 is resolving it as 0.696.
Can anyone explain what is happening here. It’s a simple calculation of the absolute value of subtracting two negative float numbers.
-
- Posts: 9723
- Joined: Thu Nov 26, 2015 4:08 am
Re: Enable double precision trigonometric functions
abs() returns an int, not a double or float. Your compiler should warn you if you try to coerce that into a double or float anyways, but if you persist, you probably get a number that does not make sense. You probably want to use fabs() instead.
Who is online
Users browsing this forum: No registered users and 151 guests