I have just realised that in pset4's short named "click" (at 2.30) here David prints out the coordinates of the click as floating point numbers. The number of pixels is finite so they could be integers. I do not see any reason to make them floats or doubles as it is also in other cases.


I have just watched that short video again. David speaks about pixels. So, the question stays. Why using variable of double type for storing number of pixels?

Can somebody explain me this?

1 Answer 1


The screen width/height is measured in pixels, but the getX and getY can be any floating number. Modern graphics libraries tend to use floating point numbers because you can draw an image "not on a pixel boundary" by using anti-aliasing. It also allows it all to work if you change the size of the screen and you don't need to worry about that.

Here's more about anti-aliasing in graphics: http://en.wikipedia.org/wiki/Spatial_anti-aliasing

  • Thank you for the answer. It is clear now about anti-aliasing in graphics. But it is difficult for me to imagine screens with resolutions sizeof(int) x sizeof(int) or higher.
    – user2477
    Oct 22, 2014 at 9:17

You must log in to answer this question.