Hi,
I work on Arduino Uno and I’m a newbie.
I’m trying to build a binary file transfer with a Windows application. Looking at the frexp() function, I wrote:
#define _SERIAL_BAUDS 115200
#define _real_value 19116.434543
#define _precision 6
void setup() {
Serial.begin(_SERIAL_BAUDS);
while (!Serial) {;}
double d = _real_value;
double md;
float f = _real_value;
float mf;
int n;
// == float print
mf = frexp(f, &n);
Serial.print("f :"); Serial.print(f, _precision);Serial.println("");
Serial.print("The mantissa is ");Serial.print(mf,_precision);Serial.print(" and the exponent is "); Serial.print(n); Serial.println("");
Serial.print("Result :"); Serial.print(mf*pow(2,n),_precision);Serial.println("");
Serial.println("");
delay(100);
// == double print
md = frexp(d, &n);
Serial.print("d :"); Serial.print(d,_precision);Serial.println("");
Serial.print("The mantissa is ");Serial.print(md,_precision);Serial.print(" and the exponent is "); Serial.print(n); Serial.println("");
Serial.print("Result :"); Serial.print(md*pow(2,n),_precision);Serial.println("");
Serial.println("");
delay(100);
}
void loop() {
while (true) {delay(1000);}
}
And the output is (copy/paste) :
f :19116.433593
The mantissa islt :19116.433593ponent is 15
Result :19116.433593d :19116.433593
The mantissa is 0.583387 and the exponent is 15
Result :19116.433593f :19116.433593
The mantissa is 0.583387 and the exponent is 15
Result :19116.433593d :19116.433593
The mantissa is 0.583387 and the exponent is 15
Result :19116.433593
:o :o :o
Why if the decimal part of real value is define as 434543, the print and the used value is 433593 !?!?
Moreover, why the float print sequence is happening twice?
Any explanations?
Thanks !