# Printing math gives inf

**URL:** <https://forum.arduino.cc/t/printing-math-gives-inf/1152364>\
**Category:** Programming\
**Created:** [July 27, 2023, 6:19pm UTC](https://forum.arduino.cc/t/printing-math-gives-inf/1152364 "2023-07-27T18:19:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PowerSoft](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/powersoft/32/1127294_2.png) [@PowerSoft](https://forum.arduino.cc/u/PowerSoft)\
**Post date:** [July 27, 2023, 6:19pm UTC](https://forum.arduino.cc/t/printing-math-gives-inf/1152364/1 "2023-07-27T18:19:46Z")

</div>

I use this code, en when printing get ovf.  
Why is this?

```arduino
typdouble xd=24.66e10,yd=32.54,zd;
float xf=12.4e+10,yf=98.67,zf;

void setup() {
  Serial.begin(115200);
  Serial.println(" test ");
  zd = xd * yd;
  Serial.println(zd);
  zf = xf * yf;
  Serial.println(zf);
}

void loop() {
  // put your main code here, to run repeatedly:

}e or paste code here

```

---

<div class="post-metadata">

**Author:** ![jfjlaros](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jfjlaros/32/716915_2.png) [@jfjlaros](https://forum.arduino.cc/u/jfjlaros)\
**Post date:** [July 27, 2023, 6:38pm UTC](https://forum.arduino.cc/t/printing-math-gives-inf/1152364/2 "2023-07-27T18:38:27Z")

</div>

From [the reference documentation](https://www.arduino.cc/reference/en/language/variables/data-types/float/):

> [@](#):
>
> Floating-point numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38.

However,

> [@PowerSoft](#):
>
> `double xd=24.66e10,yd=32.54,zd;`

`xd` is 2.466E100.

I suspect that `double` is 4 bytes on your system.

[edit]

Oops, that should be 2.466E11 as @anon94801460 said. Please disregard the explanation above.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [July 27, 2023, 6:57pm UTC](https://forum.arduino.cc/t/printing-math-gives-inf/1152364/3 "2023-07-27T18:57:26Z")

</div>

> [@jfjlaros](#):
>
> `xd` is 2.466E100.

Did you mean 2.466E11?

@PowerSoft You forgot to say which Arduino you are using, but on the Uno and others, Serial.print() does not support scientific notation, so it converts the integer part of the float/double to int32, which overflows at about 2.4e9.

Example.

```arduino
void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
while (!Serial);
float x = 2.1e9;
float y = 21.0e9;
Serial.println(x);
Serial.println(y);
}

void loop() {
  // put your main code here, to run repeatedly:
}

```

Output

```arduino
2100000000.00
ovf

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 23, 2024, 6:57pm UTC](https://forum.arduino.cc/t/printing-math-gives-inf/1152364/4 "2024-01-23T18:57:35Z")

</div>

Closed on January 23, 2024, 6:57pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
