vecdebug.c: (Matching .h file)


/* vecdebug.c routines to help debugging with the vector package.
 * © Copyright 1999 by John Halleck
 * All rights reserved.
 */
/* Version of August 16th, 1999 */

#include <stdio.h>
  /* Standard IO */

#include "errors.h"
  /* Common error codes */
#include "vec.h"
  /* Matrix specific stuff */

#include "vecdebug.h"
  /* And interfaces specific to this. */

/* --------------------- Printing ----------------------------------- */

error vecprint (char *text, int size, vector toprint) {
  if (text) printf ("%s\n", text);
  if (!toprint)  return ERRnil;
  if (size < 1)  return ERRsize;

  printf ("[");
  while (size--) printf (" %f", *toprint++);
  printf (" ]\n");

  return NoError;
}

/* ----------------------  Equality ------------------------------- */

/* Exact */
error veciseq (int size, vector a, vector b) {
  if (!a || !b) return ERRnil;
  if (size < 1) return ERRsize;

  while (size--) if (*a++ != *b++) return ERRfalse;

  return NoError;
}

/* Approximate */
error vecisaeq (int size, vector a, vector b, double fudge) {
  double diff;

  if (!a || !b) return ERRnil;
  if (size<1)   return ERRsize;

  while (size--) {
     diff = *a++ - *b++;
     if (diff < 0) diff = -diff;
     if (diff > fudge) return ERRfalse;
  }

  return NoError;
}

Go to ...


This page is http://www.cc.utah.edu/~nahaj/cave/survey/code/c/vecdebug.c.html
© Copyright 2000 by John Halleck, All Rights Reserved.
This snapshot was last modified on August 23rd, 2000
And the underlying file was last modified on May 11th, 2000