Detect literal constant kind

Dear all,

I’m currently refactoring a relatively large code where the authors use compiler flags (-r8 with ifort or -fdefault-real-8 -fdefault-double-8 with gfortran) to promote the default real kind to double precision.
I’ve managed to change the real declarations easily but it’s cumbersome to detect literal constant, like detecting 0.5 in the following line:

rij(1,3)=(xr(1,3)**2+xr(2,3)**2-xr(1,2)**2)*0.5/xr(1,3)/xr(2,3) !cos

I’ve tried to look at intermediate files generated with “-fverbose-asm -fdump-tree-original-uid” gfortran compiler flags, but the literal constant kind doesn’t appear (or I don’t see it).

Do you know a way with compiler flags or something else to detect the literal constant kind?

If you are worried about a possible loss of precision, you could try gfortran with the flag -Wall (the relevant flag is, I think, -Wconversion). gfortran is very good at catching problematic conversions. You could also try setting the default compiler precision to a higher-precision kind type parameter than what you use for variable declarations such as rij and xr in your expression. This will force Gfortran to emit a warning for all assignments that lead to a loss of precision due to mixing the precision of default constants with variables of lower precision. An ultimate solution could be to write a Python script to parse all literals.

Thanks
Indeed, I’m worried about losing precision. It was the case. I manually caught most of the literal constants with the wrong kind.

The -Wall and/or -Wconversion flags don’t work, or they are no longer problematic conversions.

If you are on Windows and have Notepad++, you could also try the following regex

(\d*)(\.)+(\d*)

after pressing ctrl + f and selecting “regular expression” in the left corner of the panel. This seems to work well in finding all numeric patterns with a period, although it will also find single periods in the files (for example, at the end of the sentence in the comments). However, the numbers can be readily spotted in the search results.

Thanks.
I don’t have notepad++, but with vscode, you can search with regex.
For a small file, it seems to work.