Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generics: add example of any kind #1804

Open
certik opened this issue Jun 12, 2023 · 0 comments
Open

Generics: add example of any kind #1804

certik opened this issue Jun 12, 2023 · 0 comments

Comments

@certik
Copy link
Contributor

certik commented Jun 12, 2023

Here is one:

https://fortran-lang.discourse.group/t/can-floating-point-literals-be-adapted-by-the-compiler-to-double-precision-variable/2034/102

template log10_tmpl(k)
  integer, constant :: k
  private
  public :: log10
  interface log10
    procedure log10_local
  end interface
contains
  simple elemental function log10_local(x) result(r)
    real(k), intent(in) :: x
    real(k) :: r
    r = log(x) / log(10._k)
  end function
end template

and you use it like:

use kinds_m, only: wp

instantiate log10_tmpl(wp)
real(wp) :: x, y
x = 42._wp
y = log10(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant