Joined: 20 Dec 2007
Location: Piliyandala,Sri lanka
floating point arithmatics
hello,i'm trying learn addition of 2 floating point numbers with the code(attached) bellow.when adding same numbers two times they give different results(well results are in other way round and it is not the problem)
can someone please explain me why two results (addition1 and addition2 in the code)for same numbers?
The problem is that you made your text buffers only one byte large. The first binary value that is printed out is correct, but when you created the string in buffer num1, you ended up overwriting the floating point constants. Therefore, the second time you tried to add the numbers together, float4 and float5 weren't equal to 9.45 and 5.22 anymore. They were destroyed.
If you had put your float constants before your text buffers, it would've worked correctly as well. Or... you could expand num1 and num2 to cover 33 bytes each, like I suggested above.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum