[7314] in Athena Bugs

home help back first fref pref prev next nref lref last post

vax 7.2R: gcc

daemon@ATHENA.MIT.EDU (daemon@ATHENA.MIT.EDU)
Thu Mar 14 22:40:56 1991

From: jldelcal@ATHENA.MIT.EDU
To: bugs@ATHENA.MIT.EDU
Date: Thu, 14 Mar 91 22:40:37 EST

System name:		test-2000
Type and version:	VAXSTAR 7.2R
Display type:		SM

What were you trying to do?
run one of my programs compiled using gcc.  here is a sample:

#include<stdio.h>
#include<math.h>
#define MASS 4e3
#define BIGK 4e6
#define PI 3.1415927

void create_k_inverse_x1_and_m(double *K, double *M, double x1[], int n);
void sqr_mat_vec_mult(double *A, double b[], double c[], int n);
double find_max_in_vec(double x[], int n);
void scale_vec(double x[], double scale, int n);
double do_iterations(double tolerance, int n);
double do_one_iteration(double *K, double *M, double x1[], int n);

main()
{
  int height;
  double tolerance, fn;

  printf("enter desired tolerance:             ");
  scanf("%lf", &tolerance);
  printf("\nenter number of storeys of building: ");
  scanf("%i", &height);       /*an error occurs just after this */
                              /*before do_iterations is called  */
                              /*it signals floating exception   */
                              /*without any operation on a float*/
  fn = do_iterations(tolerance, height);
  printf("\nfn = %lf\n", fn);
}

double do_iterations(double tolerance, int n)
{
  double K[n][n], M[n][n], x1[n];
  int i;
  double omega, omegaprev, t1, fn;

  printf("chkpt");

  omegaprev = do_one_iteration(&K[0][0], &M[0][0], x1, n);
  omega = do_one_iteration(&K[0][0], &M[0][0], x1, n);
  t1 = fabs(omega - omegaprev);
  
  create_k_inverse_x1_and_m(&K[0][0], &M[0][0], x1, n);
  while (t1 > tolerance){
    printf("%8.4lf\n", t1);
    omegaprev = omega;
    omega = do_one_iteration(&K[0][0], &M[0][0], x1, n);
    t1 = fabs(omega - omegaprev);
  }

  fn = sqrt(omega)/(2*PI);
  return(fn);
}

double do_one_iteration(double *K, double *M, double x1[], int n)
{
  double q[n], phi[n];
  double omega;

  printf("hurro");
  sqr_mat_vec_mult(M, x1, q, n);
  sqr_mat_vec_mult(K, q, phi, n);
  omega = find_max_in_vec(x1, n) / find_max_in_vec(phi, n);

  return(omega);
}

void scale_vec(double x[], double scale, int n)
{
  int i;
  for(i=0; i<n; i++)
    x[i] = x[i] * scale;
}

void create_k_inverse_x1_and_m(double *K, double *M, double x1[], int n)
{
  int i, j;
  double invk = 1 / BIGK;

  for(i=0; i<n; i++){
    for(j=i; j<n; j++){
      *(M+i*n+j) = 0;
      *(K+i*n+j) = (i + 1) * invk;
    }
    for(j=i+1; j<n; j++){
      *(M+j*n+i) = 0;
      *(K+j*n+i) = (i + 1) * invk;
    }
    *(M+i*n+i) = MASS;
    x1[i] = 1;
  }
}

void sqr_mat_vec_mult(double *A, double b[], double c[], int n)
{
  double sum;
  int i,j;
  for(i=0; i<n; i++){
    sum = 0.0;
    for(j=0; j<n; j++)
      sum = sum + *(A+i*n+j)*b[j];
    c[i] = sum;
  }
}

double find_max_in_vec(double x[], int n)
{
  double max;
  int i;
  max = x[0];
  for(i=1; i<n; i++)
    if (x[i] > max)
      max = x[i];
  return(max);
}


What's wrong:
it signalled floating exception where commented.  i put checkpoints to find out
where it happened.  this is where the error occured.

What should have happened:
any error message, if any, should not have been signalled from the area pointed
out by the comment.

Please describe any relevant documentation references:
the program is above.

home help back first fref pref prev next nref lref last post