esp8266 / esp8266/Arduino

Calling round() inside print() result differs between v2.4.2 and v2.5.0-beta2

Open
#5,530 8 comments 0 reactions 1 assignee Claimed by @devyte View on GitHub
component: core type: code cleanup
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

### Basic Infos

- [Y] This issue complies with the [issue POLICY doc](https://github.com/esp8266/Arduino/blob/master/POLICY.md).
- [Y] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [N] I have tested that the issue is present in current master branch (aka latest git). I simply upgraded the IDE to 2.5.2-beta2 and then compared it with 2.4.2 behaviour and observed an unexpected and unwelcome difference.
- [Y] I have searched the issue tracker for a similar issue.
- [N/A] If there is a stack dump, I have decoded it.
- [Y] I have filled out all fields below.

#### Platform

- Hardware: [ESP8286]
- Core Version: [2.5.0-beta2 & 2.4.2]
- Development Env: [Arduino IDE]
- Operating System: [MacOS]

### Settings in IDE

- Module: [Wemos D1 mini r2]
- Flash Mode: [dio - as far as I am aware]
- Flash Size: [4MB/1MB]
- lwip Variant: [v2 Lower Memory]
- Reset Method: [whatever the IDE does at the end of a download]
- Flash Frequency: [no menu item for this - can't answer]
- CPU Frequency: [80Mhz]
- Upload Using: [SERIAL]
- Upload Speed: [921600)

### Problem Description

Under version 2.4.2, round() appears to return an integer quantity. Under 2.5.0-beta2, round() appears to return a real quantity. I am inferring this from a change in print() behaviour.

### [MCVE](https://stackoverflow.com/help/mcve) Sketch

```cpp

#include

void setup() {

Serial.begin(115200);
while (!Serial);
delay(100);
Serial.println();
Serial.println();

}

void loop() {

// wait a while
delay(1511);

// precalculate upTime to the nearest second
unsigned long upTime = round(millis()/1000.0);

// display upTime with an inline calculation
Serial.print("Up time: inline = ");
Serial.print(round(millis()/1000.0));
Serial.print(", pre-calculated = ");
Serial.println(upTime);

}

```

### Debug Messages

Output from compiling under 2.4.2 libraries. Note ABSENCE of decimal places for "inline =" values. This is the expected behaviour.

```
Up time: inline = 2, pre-calculated = 2
Up time: inline = 3, pre-calculated = 3
Up time: inline = 5, pre-calculated = 5
Up time: inline = 6, pre-calculated = 6
Up time: inline = 8, pre-calculated = 8
Up time: inline = 9, pre-calculated = 9
Up time: inline = 11, pre-calculated = 11
Up time: inline = 12, pre-calculated = 12
...
```

Output from compiling under 2.5.0-beta2 libraries. Note PRESENCE of decimal places for "inline =" values. This suggests print() is treating the return value from round() as a real quantity. This is unexpected.

```
Up time: inline = 2.00, pre-calculated = 2
Up time: inline = 3.00, pre-calculated = 3
Up time: inline = 5.00, pre-calculated = 5
Up time: inline = 6.00, pre-calculated = 6
Up time: inline = 8.00, pre-calculated = 8
Up time: inline = 9.00, pre-calculated = 9
Up time: inline = 11.00, pre-calculated = 11
Up time: inline = 12.00, pre-calculated = 12
...
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.