Working with large floating point numbers.

lordreas
Posts: 2
Joined: Tue Mar 14, 2023 11:35 pm

Working with large floating point numbers.

Postby lordreas » Tue Mar 14, 2023 11:50 pm

Hello there,

I'm struggling with calculations involving large floats. Running the following code on my Wemos Lolin32 Lite on Arduino featuring an ESP-32 Rev1

Code: Untitled.cpp Select all


double test = 2.;

void setup() {
// put your setup code here, to run once:
Serial.begin(31250);
}

void loop() {
// put your main code here, to run repeatedly:
test*=1.1;
Serial.println(test);
}
leading to the following output after some time:

Code: Select all

3400938557.93
3741032413.72
4115135655.09
ovf
ovf
ovf
4115135655.09 is way below theoretical limits of float (3e38) let alone double (1e308). What's happening here? I know Esp32 is not the best number for fast or precise FLOPs, but something else but precision seems to be wrong here.

I would be glad if someone could reproduce this / help me / hint me at other resources, thanks in advance!

Sprite
Espressif staff
Espressif staff
Posts: 10596
Joined: Thu Nov 26, 2015 4:08 am

Re: Working with large floating point numbers.

Postby Sprite » Wed Mar 15, 2023 12:19 am

That overflow seems to happen at the limit of a 32-bit integer. I'd guess the double variable itself doesn't overflow; it's the println routine that messes up. Perhaps you can see what happens if you replace that with a printf("%f\n", test); ?

Who is online

Users browsing this forum: Google [Bot] and 6 guests