Example #1
0
static VALUE rb_gsl_ieee_fprintf_double(int argc, VALUE *argv, VALUE obj)
{
#ifdef RUBY_1_9_LATER
  rb_io_t *fptr = NULL;
#else
  OpenFile *fptr = NULL;
#endif
  FILE *fp = NULL;
  int flag = 0;
  VALUE vtmp;

  switch (argc) {
  case 2:
    switch (TYPE(argv[0])) {
    case T_STRING:
      fp = fopen(RSTRING_PTR(argv[0]), "w");
      flag = 1;
      break;
    case T_FILE:
      GetOpenFile(argv[0], fptr);
      rb_io_check_writable(fptr);
#ifdef RUBY_1_9_LATER
      fp = rb_io_stdio_file(fptr);
#else
      fp = GetWriteFile(fptr);
#endif
      break;
    default:
      rb_raise(rb_eTypeError, "wrong type argument %s (IO or String expected)",
	       rb_class2name(CLASS_OF(argv[0])));
    }
    vtmp = argv[1];
    break;
  case 1:
    vtmp = argv[0];
    fp = stdout;
    break;
  default:
    rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
  }
  if (TYPE(vtmp) != T_FLOAT)
    rb_raise(rb_eTypeError, "wrong argument type %s (Float expected)",
	     rb_class2name(CLASS_OF(vtmp)));
#ifdef RUBY_1_9_LATER
  double rbfv = rb_float_value(vtmp);
  gsl_ieee_fprintf_double(fp, &rbfv);
#else
  gsl_ieee_fprintf_double(fp, &(RFLOAT(vtmp)->value));
#endif
  if (fp == stdout) fprintf(stdout, "\n");
  if (flag == 1) fclose(fp);
  return obj;
}
Example #2
0
void 
gsl_ieee_printf_double (const double * x)
{
  gsl_ieee_fprintf_double (stdout,x);
}
Example #3
0
int
main (void)
{
  size_t i = 0;
  const double tol = TEST_FACTOR * 10 * GSL_DBL_EPSILON;
  const double tolf = TEST_FACTOR * 10 * GSL_FLT_EPSILON;

  gsl_ieee_env_setup();


  for (i = 0 ; i < 10; i++) 
    {
      double r = (i - 5.0) * 0.3 ;
      double t = 2.0 * M_PI * i / 5 ;
      double x = r * cos(t), y = r * sin(t) ;
      gsl_complex z = gsl_complex_polar (r, t) ;
      gsl_test_rel (GSL_REAL(z), x, tol, "gsl_complex_polar real part at (r=%g,t=%g)", r, t);
      gsl_test_rel (GSL_IMAG(z), y, tol, "gsl_complex_polar imag part at (r=%g,t=%g)", r, t);
    }
    
    i = 0;

  while (list[i].f)
    {
      struct f t = list[i];
      gsl_complex z = gsl_complex_rect (t.x, t.y);
      double f = (t.f) (z);
      gsl_test_rel (f, t.fx, tol, "%s at (%g,%g)", t.name, t.x, t.y);
      i++;
    }

  i = 0;

  while (listz[i].f)
    {
      struct fz t = listz[i];
      gsl_complex z = gsl_complex_rect (t.x, t.y);
      gsl_complex fz = (t.f) (z);
      double fx = GSL_REAL (fz), fy = GSL_IMAG (fz);

#ifdef DEBUG
      printf("x = "); gsl_ieee_fprintf_double (stdout, &t.x); printf("\n");
      printf("y = "); gsl_ieee_fprintf_double (stdout, &t.y); printf("\n");
      printf("fx = "); gsl_ieee_fprintf_double (stdout, &fx); printf("\n");
      printf("ex = "); gsl_ieee_fprintf_double (stdout, &t.fx); printf("\n");
      printf("fy = "); gsl_ieee_fprintf_double (stdout, &fy); printf("\n");
      printf("ey = "); gsl_ieee_fprintf_double (stdout, &t.fy); printf("\n");
#endif

      gsl_test_rel (fx, t.fx, tol, "%s real part at (%g,%g)", t.name, t.x, t.y);
      gsl_test_rel (fy, t.fy, tol, "%s imag part at (%g,%g)", t.name, t.x, t.y);
      i++;
    }

  i = 0;

  while (listzz[i].f)
    {
      struct fzz t = listzz[i];
      gsl_complex z1 = gsl_complex_rect (t.x1, t.y1);
      gsl_complex z2 = gsl_complex_rect (t.x2, t.y2);
      gsl_complex fz = (t.f) (z1, z2);
      double fx = GSL_REAL (fz), fy = GSL_IMAG (fz);

#ifdef DEBUG
      printf("x1 = "); gsl_ieee_fprintf_double (stdout, &t.x1); printf("\n");
      printf("y1 = "); gsl_ieee_fprintf_double (stdout, &t.y1); printf("\n");
      printf("x2 = "); gsl_ieee_fprintf_double (stdout, &t.x2); printf("\n");
      printf("y2 = "); gsl_ieee_fprintf_double (stdout, &t.y2); printf("\n");
      printf("fx = "); gsl_ieee_fprintf_double (stdout, &fx); printf("\n");
      printf("ex = "); gsl_ieee_fprintf_double (stdout, &t.fx); printf("\n");
      printf("fy = "); gsl_ieee_fprintf_double (stdout, &fy); printf("\n");
      printf("ey = "); gsl_ieee_fprintf_double (stdout, &t.fy); printf("\n");
#endif

      gsl_test_rel (fx, t.fx, tolf, "%s real part at (%g,%g;%g,%g)", t.name, t.x1, t.y1, t.x2, t.y2);
      gsl_test_rel (fy, t.fy, tolf, "%s imag part at (%g,%g;%g,%g)", t.name, t.x1, t.y1, t.x2, t.y2);
      i++;
    }


  i = 0;

  while (listreal[i].f)
    {
      struct freal t = listreal[i];
      gsl_complex fz = (t.f) (t.x);
      double fx = GSL_REAL (fz), fy = GSL_IMAG (fz);

#ifdef DEBUG
      printf("x = "); gsl_ieee_fprintf_double (stdout, &t.x); printf("\n");
      printf("fx = "); gsl_ieee_fprintf_double (stdout, &fx); printf("\n");
      printf("ex = "); gsl_ieee_fprintf_double (stdout, &t.fx); printf("\n");
      printf("fy = "); gsl_ieee_fprintf_double (stdout, &fy); printf("\n");
      printf("ey = "); gsl_ieee_fprintf_double (stdout, &t.fy); printf("\n");
#endif

      gsl_test_rel (fx, t.fx, tol, "%s real part at (%g,0)", t.name, t.x);
      gsl_test_rel (fy, t.fy, tol, "%s imag part at (%g,0)", t.name, t.x);
      i++;
    }

  exit (gsl_test_summary ());
}