Skip to content

Latest commit

 

History

230 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arithmetic_geometric_mean_fortran

A Fortran library for computing the arithmetic-geometric mean (AGM) of two non-negative floating-point numbers.

CI

Features

  • Support for real32, real64, and real128 precision
  • 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

Requirements

Fortran compiler with support for:

  • iso_fortran_env intrinsic module
    • real32, real64 types (required)
    • real128 type (optional, compiler-dependent)
  • ieee_arithmetic intrinsic module
    • ieee_quiet_nan
    • ieee_unordered
    • ieee_value

Installation

Option 1: Using fpm

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" }

Option 2: Manual Integration

Since this library consists of a single source file, so that you can

  1. Download arithmetic_geometric_mean_fortran.f90
  2. Include it in your compilation

API Reference

Functions

interface description
arithmetic_geometric_mean Computes AGM with automatic input validation
arithmetic_geometric_mean_kernel Computes AGM without automatic input validation

Types

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

Examples

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 examples

The --profile subcommand is also available.

Testing

Run tests using fpm:

fpm test --profile debug
fpm test --profile release

Documentation

Documentation