C/C++ math service examples

Table 1 shows code examples of calling various math services from C/C++.

Table 1. C/C++ examples
Function called Code example
Log base 10 and modular arithmetic (CEESDGL1 and CEESIMOD)
#include <leawi.h>
#include <string.h>
#include <stdio.h>

int main (void) {

  _FLOAT8 f1,result;
  _INT4 int1, int2, intr;

  _FEEDBACK fc;
  #define SUCCESS "\0\0\0\0"

  f1 = 1000.0;

  CEESDLG1(&f1,&fc,&result);

  if (memcmp(&fc,SUCCESS,4) != 0) {
     printf("CEESDLG1 failed with message number %d\n",
            fc.tok_msgno);
     exit(2999);
  }

  printf("%f log base 10 is %f\n",f1,result);

  int1 = 39;
  int2 = 7;
  CEESIMOD(&int1,&int2,&fc,&intr);

  if (memcmp(&fc,SUCCESS,4) != 0) {
     printf("CEESIMOD failed with message number %d\n",
            fc.tok_msgno);
     exit(2999);
  }

  printf("%d modulo %d is %d\n",int1,int2,intr);
}