Enable double precision trigonometric functions

alsaleem00
Posts: 8
Joined: Tue Oct 06, 2020 12:40 pm

Enable double precision trigonometric functions

Postby alsaleem00 » Tue Dec 29, 2020 10:06 pm

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.

ESP_Jan
Posts: 42
Joined: Tue Dec 01, 2020 10:56 am

Re: Enable double precision trigonometric functions

Postby ESP_Jan » Wed Dec 30, 2020 12:58 pm

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

tommeyers
Posts: 184
Joined: Tue Apr 17, 2018 1:51 pm
Location: Santiago, Dominican Republic

Re: Enable double precision trigonometric functions

Postby tommeyers » Wed Dec 30, 2020 12:59 pm

Example code? Results ?
IT Professional, Maker
Santiago, Dominican Republic

Victoria Nope
Posts: 75
Joined: Fri Dec 04, 2020 9:56 pm

Re: Enable double precision trigonometric functions

Postby Victoria Nope » Sun Jan 03, 2021 1:54 pm

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?

alsaleem00
Posts: 8
Joined: Tue Oct 06, 2020 12:40 pm

Re: Enable double precision trigonometric functions

Postby alsaleem00 » Sun Jan 31, 2021 10:28 am

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.

baamiis777
Posts: 1
Joined: Sun Oct 31, 2021 2:26 am

Re: Enable double precision trigonometric functions

Postby baamiis777 » Sun Nov 28, 2021 1:46 pm

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.

ESP_Sprite
Posts: 9723
Joined: Thu Nov 26, 2015 4:08 am

Re: Enable double precision trigonometric functions

Postby ESP_Sprite » Mon Nov 29, 2021 1:56 am

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: Google [Bot] and 106 guests