A Fortran library for computing the arithmetic-geometric mean (AGM) of two non-negative floating-point numbers.
- Support for
real32,real64, andreal128precision - Elemental functions (works with scalars and arrays)
- Two computation interfaces:
- Lightweight functions: Fast computation returning only the final AGM value
- Type-bound methods: Full computation with iteration history storage for convergence analysis
- Single-file library for easy integration
Fortran compiler with support for:
iso_fortran_envintrinsic modulereal32,real64types (required)real128type (optional, compiler-dependent)
ieee_arithmeticintrinsic moduleieee_quiet_nanieee_unorderedieee_value
To use this library within your fpm project, add the following to your package fpm.toml file:
[dependencies]
arithmetic_geometric_mean_fortran = { git = "https://github.com/DSCF-1224/arithmetic_geometric_mean_fortran.git" }Since this library consists of a single source file, so that you can
- Download
arithmetic_geometric_mean_fortran.f90 - Include it in your compilation
| interface | description |
|---|---|
arithmetic_geometric_mean |
Computes AGM with automatic input validation |
arithmetic_geometric_mean_kernel |
Computes AGM without automatic input validation |
arithmetic_geometric_mean_real32_typearithmetic_geometric_mean_real64_typearithmetic_geometric_mean_real128_type
Each type provides:
| procedure | type | description |
|---|---|---|
compute |
subroutine | Type-bound subroutine that performs AGM computation and stores iteration history |
max |
interface | Extracts the final AGM value / AGM value at a specific iteration |
min |
interface | Extracts the final AGM value / AGM value at a specific iteration |
n_iter |
function | Returns the number of iterations performed |
gap |
interface | Extracts the final gap (a-g) / gap at a specific iteration |
| program | description |
|---|---|
demo_basic_usage |
Demonstrates both function and type-bound interfaces |
demo_n_iter |
Shows how to access iteration history |
Run examples using fpm:
fpm run --example demo_basic_usage
fpm run --example demo_n_iter
fpm run --example # Run all examplesThe --profile subcommand is also available.
Run tests using fpm:
fpm test --profile debugfpm test --profile release