Interesting.. Seems like Apple's NSDeviceResolution may be acting as a backwards-compatibility bodge.
But TBH even this other trick will get the wrong value sometimes, because there will inevitably be monitors where the OS simply has no idea what their size is. (e.g. what does this return if you connect a projector!?)
If Extended Display Identification Data (EDID) for the display device is not available, the size is estimated based on the device width and height in pixels from CGDisplayBounds, with an assumed resolution of 2.835 pixels/mm or 72 dpi, a reasonable guess for displays predating EDID support.