Hi guys, this may seem like a newbie type of question but i'm really stumped on this one. I want to use the sqrt() function from math.h on two variables which are unsigned int. if i do: unsigned int Id, Iq; double temp; Id = ///some function call temp = (double)Id; and assuming Id contains say 0x2700, after executing the 3rd line, temp = 0, not 9984 as it should. Does anyone know how I can convert from unsinged int to double besides the way I've tried. thanks a lot. Nick
The statement about code being fine if it runs ok on the simulator is mostly true there are many more examples of the "OK on simulator does not mean OK". For instance you can run just fine on the simulator withour debounce, try that in real life. A simulator can be excellent for some things, but it is no "proofer" Erik
But this is different: he says it works in his target, but not in the simulator! This could, of course, still be undefined behaviour - and he just happens to be lucky on his real target... (actually, he just said he couldn't view the variable in the simulator; he didn't actually say that it didn't work - hence my earlier follow-up question)
Hi Guys, Thank you all for your replies. Andrew: the code did not function correctly in the simulator to begin with, converting to double (or float) from unsigned int would give me zero, not the value it should have given me, and yes, I am stepping at the assembler level in the simulator and watching variable contents as each assemly line is executed. When I run the same code in the debugger with my 8051 board connected (8051 executing code, and not the simulator), the type conversion works correctly (this is all I need because in the real world my code will run on my target board, not the simulator). Jay, even if I use float, I have the same problem - code works correctly on the target board, but not in the simulator. Erik, I wasn't talking about a harware issue like a switch debounce, but I appreciate your comments - Simulator is just a proofer. Ultimately, the code works correctly on the actual target board so I'm satisfied. Thank you all for your input. -Nick
Ooops, I meant "Simulator is not a 100% proofer" Nick