NAG Library Manual, Mark 28.5
Interfaces:  FL   CL   CPP   AD 

NAG CL Interface Introduction
Example description
/* nag_specfun_hyperg_gauss_real (s22bec) Example Program.
 *
 * Copyright 2022 Numerical Algorithms Group.
 *
 * Mark 28.5, 2022.
 */

#include <nag.h>
#include <stdio.h>

void construct_table(double a, double b, double c);

int main(void) {
  /* Scalars */
  Integer exit_status = 0;
  Integer kx;
  double a, b, c, f, x;
  /* Nag Types */
  NagError fail;

  INIT_FAIL(fail);

  printf("nag_specfun_hyperg_gauss_real (s22bec) Example Program Results\n\n");

  a = 1.2;
  b = -2.6;
  c = 3.5;

  construct_table(a, b, c);

  for (kx = 1; kx < 22; kx++) {
    x = -4.0 + ((double)(kx - 1)) * 0.25;
    /* Evaluate Real Gauss hypergeometric function 2F1(a,b;c;x) using
     * nag_specfun_hyperg_gauss_real (s22bec).
     */
    f = nag_specfun_hyperg_gauss_real(a, b, c, x, &fail);
    switch (fail.code) {
    case NE_NOERROR:
    case NW_UNDERFLOW_WARN:
    case NW_SOME_PRECISION_LOSS:
    case NE_TOTAL_PRECISION_LOSS:
      printf("    %10.2f     %10.4f\n", x, f);
      break;
    case NE_INFINITE:
    case NW_OVERFLOW_WARN:
    case NE_OVERFLOW:
      if (f >= 0.0)
        printf("    %10.2f   %13s\n", x, "+Infinity");
      else
        printf("    %10.2f   %13s\n", x, "-Infinity");
      break;
    case NE_CANNOT_CALCULATE:
      printf("    %10.2f   %13s\n", x, "NaN");
      break;
    default:
      printf(" Illegal parameter.");
      exit_status = 1;
      goto END;
      break;
    }
  }
END:
  return exit_status;
}

void construct_table(double a, double b, double c) {
  printf("            a              b              c\n");
  printf("+--------------+--------------+--------------+\n");
  printf("    %10.2f     %10.2f     %10.2f\n\n", a, b, c);
  printf("            x    2F1(a,b;c;x)\n");
  printf("+--------------+--------------+\n");
  return;
}