round bug

Jake

Well-known member
I inserted a round function into my code and it complained during compilation. It turns out that the wiring.h has a #define round, that conflicts with the c round function.

The following code will not compile until the line with the round function is commented out.

Code:
// comment out the next line and all works
double yd = round(sqrt(PI));
float yf = roundf(sqrt(PI));
long int yi =roundl(sqrt(PI));

void setup() {
  // put your setup code here, to run once:

}

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

}

The wiring.h file has the command on line 80

Code:
#define round(x) ({ \
  typeof(x) _x = (x); \
  (_x>=0) ? (long)(_x+0.5) : (long)(_x-0.5); \
})
 
Yeah, this is a tough one. Should Teensy strive for compatibility with Arduino or pure C. Usually Arduino compatibility is the goal, when the 2 are at odds with each other.
 
And note, the macro in wiring.h produces the wrong answers if the value of x is larger than what can be stored into a long variable, or is -0.0.
 
Back
Top