Page 1 of 1
Enable double precision trigonometric functions
Posted: Tue Dec 29, 2020 10:06 pm
by alsaleem00
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.
Re: Enable double precision trigonometric functions
Posted: Wed Dec 30, 2020 12:58 pm
by ESP_Jan
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
Re: Enable double precision trigonometric functions
Posted: Wed Dec 30, 2020 12:59 pm
by tommeyers
Example code? Results ?
Re: Enable double precision trigonometric functions
Posted: Sun Jan 03, 2021 1:54 pm
by Victoria Nope
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?
Re: Enable double precision trigonometric functions
Posted: Sun Jan 31, 2021 10:28 am
by alsaleem00
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.
Re: Enable double precision trigonometric functions
Posted: Sun Nov 28, 2021 1:46 pm
by baamiis777
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.
Re: Enable double precision trigonometric functions
Posted: Mon Nov 29, 2021 1:56 am
by ESP_Sprite
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.