How useful is selected_int_kind and selected_real_kind?

This has been discussed many times here, just search for “selected_real_kind”, some links from quick search:

I personally do not like the current situation in Fortran, I think the selected_real_kind is a leaky abstraction, because it seems to suggest that one can use it to write Fortran code that is independent of the machine floating point implementation details. But in practice based on my experience you can’t, you typically have to assume single or double IEEE implementation. Others are rarely used, but if instead of IEEE double it was some other implementation (that some machines used to have 40 years ago), my codes would almost for sure not run correctly.

I do think the goal of Fortran should be to allow writing code that is platform independent and highly performing.

But for that, you would need better compiler (and possibly language) support that would emulate other floating point implementations (such as Cray floating point and others), or somehow guarantee the code to give accurate answers, either by compile time guarantees, or runtime guarantees. It might still be a research problem.

That being said, I do use language constructs like epsilon, tiny, etc. But just using those is not enough to guarantee that the code will work with any floating point implementation.

6 Likes