Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29261 Discussions

Wanted: Reliable Integer -> Real -> Integer conversion

anthonyrichards
New Contributor III
476 Views
I am converting some Mathcad code to Fortranroutinesand need a reliable method of storing Integers as reals and then converting them back to Integer for use as array subscripts, without having rounding problems with the reals. Suggestions would be appreciated.
0 Kudos
2 Replies
TimP
Honored Contributor III
476 Views
I can't read between your lines, so I may be missing your point. A real data type can hold integers exactly, up to intval <= 1/EPSILON(realval). If you can use selected_int_kind and selected_real_kind, you can choose data types, within limits, such that all the integers fit in the real data type.
For your real to integer conversions, you may want
intval = nint(realval,kind(intval))
0 Kudos
anthonyrichards
New Contributor III
476 Views
Thanks.
0 Kudos
Reply