next up previous

3.3 Numeric Polymorphism     continued...

In the SMOOTH example notice that the argument (AA) is a different type in each case but the function result is the same type (INTEGER in each case). The function result could also have been different in some or all cases. The only requirement for such a generic set is that the type/kind/rank pattern for the set of dummy arguments be unique in each specific case. In the COS example, note the conceptual similarity with the extension of the ``+" operator in section 1 on page 1, User Defined Types and Operators.

These generic definition capabilities make it practical for the programmer to specify precision with the SELECTED_REAL_KIND function. The program can then be geared toward the optimal precision for the application rather than focussing on the specific precisions provided by the implementation. This not only is a more natural way to develop numerical software, but it contributes to numerical robustness as well. Fortran 77, C, and Fortran 90 versions of (one variation of) the routine SMOOTH are given in section 2.1.