# Half precision in Fortran

To improve the time efficiency of my code, I'd like to test a lower precision for real number, using e.g. half precision (2 bytes).

However, I'm not sure if I can do that in Fortran. After playing with the intrinsic SELECTED_REAL_KIND procedure, it seems that gfortran can only deal with 4, 8, 10 or 16 bytes precisions.

Edit: Actually, I could have directly read the manual...

Is it then possible to use half precision floats in Fortran (maybe with another compiler)?

If not, would there be an easy alternative to prototype half precision code?

• As far as I know, Fortran recognizes 4 byte floats (single precision, iso_fortran_env :: real32, iso_c_binding :: c_float, etc) as the smallest floating point data type. Are you sure that the 8 and 10 are separate floating point precisions? – cbcoutinho Aug 2 '17 at 14:53
• Out of curiosity, what operation does your code do that you only need 3 digits of precision? I've never seen this before. – sssssssssssss Aug 2 '17 at 15:30
• @cbcoutinho I tried SELECTED_REAL_KIND with several arguments and got the integers 4, 8, 10 and 16 (and some error codes) as results. I assume those are the available precisions in bytes. (80 bits precision is a thing according to Wikipedia). – Matthieu Aug 2 '17 at 15:52
• @Steve For parametric studies and optimization problems. Since I'm running a lot of “simple” independent computations, the rounding errors should not pile up too much. And 3 digits can be sufficient to discard the worse solutions in an optimization algorithm. – Matthieu Aug 2 '17 at 16:00
• Most modern CPUs have instructions that perform floating point operations on IEEE standard single (4-byte) and double precision (8-byte) numbers. So, unless you are running on an unusual CPU, the best performance is likely to be with 4-byte floats. – Bill Greene Aug 2 '17 at 16:33