Hello people,
i am having trouble getting a correct value of double using "pgm_read_dword", does anyone have any idea why this happens?
const PROGMEM double d = 3.12;
const PROGMEM float f = 3.12;
void setup() {
Serial.begin(9600);
Serial.println( pgm_read_dword( &d ) );
Serial.println( pgm_read_float( &f ) );
}
void loop() {}
outputs:
1078439444
3.12
Thanks in advance,
George
Because the unsigned integer interpretation of a float value gives that value.
double and float are the same, dword is an unsigned int of 32 bits on most Arduinos.
Whandall:
Because the unsigned integer interpretation of a float value gives that value.
double and float are the same, dword is an unsigned int of 32 bits on most Arduinos.
i know but i need double and not a float because i need high floating point precision for my library.
Thanks for replying, i 've actualy realised that dword is an unsigned int of 32 bits from this link but how can i get the actual double number? do you know how?
demkat1:
Giorgos,
ellada?
Naiiii!!! (: (: (:
There are no double precision floats in standard Arduinos IIRC.
i dont care about standar Arduinos, unless it has to do with the fact that i am compiling that code on an arduino and not on another development board and thats why the outputs are strange :P, i just need somehow to convert that unsigned int of 32 bits back to double, do you know how?
You never had a double, it was always a float.
A double would use 8 bytes, so reading the first half of that would be senseless anyway.
i just compiled this "Serial.println( pgm_read_float( &d ) ); //d is a "double" " and it worked! you are right! i was confused! because i thought that arduino uno supported double precision, now its clear , thanks you very much! you solved my problem! 
Giorgos_xou:
i just compiled this "Serial.println( pgm_read_float( &d ) ); //d is a "double" " and it worked! you are right! i was confused! because i thought that arduino uno supported double precision, now its clear , thanks you very much! you solved my problem! 
How could that solve your basic problem?
Giorgos_xou:
i need double and not a float because i need high floating point precision for my library.
i know its comfusing but, actualy it didnt but at the same time it did solve my problem lol, because i've realised that float precision is actualy enough for my needs at this moment that i have two libraries one that uses SRAM and one the PROGMEM. [...]
(double was always a float on the arduino uno i was using and was testing my library)
+"Serial.println( pgm_read_float( &d ) ); //d is a "double" " i know that this is wrong even if it work on an arduino , i am going to use floats instead of doubles