-3

I currently programming some calculations and found a weird issue, which I cannot explain. I'm doing a calculation which I save in a new double field. The thing is, that the finally saved value is not the same than the solution of the formula. I made a screenshot for better understanding.

When I put the whole calculation in a watch, I get the result "1.3050....." When i check the double afterwards, it has saved "2.87......." which I have no idea, where that comes from. Does anybody know, why it is behaving like this? For me thats absolutely unexplainable... enter image description here

Full size: https://i.stack.imgur.com/8nJpn.png

Herr Derb
  • 4,977
  • 5
  • 34
  • 62
  • 2
    Please post some code, not a screenshot. Can you not see that it's impossible to see what you have coded? – Boris the Spider May 15 '14 at 19:32
  • 1
    You can see it better if you copy picture URL and post in a new tab, but yeah, code is better.. With that said, I'm not sure what's really going on, but the Math.PI/180 would be better as Math.PI/180.0. You also didn't tell us the value of Constants.CAM_OFFSET – EyeOfTheHawks May 15 '14 at 19:33
  • @EyeOfTheHawksNot only useful, that was actually the problem... thanks for the hint :) – Herr Derb May 15 '14 at 19:36
  • Alright I'll submit it as an answer – EyeOfTheHawks May 15 '14 at 19:36
  • possible duplicate of [Odd behaviors when dividing doubles in Java](http://stackoverflow.com/questions/13668007/odd-behaviors-when-dividing-doubles-in-java) – Paul Hicks May 15 '14 at 21:00

1 Answers1

1

Math.PI/180 should be Math.PI/180.0, dividing doubles by integers will cause some funny things to happen

EyeOfTheHawks
  • 576
  • 1
  • 5
  • 16