Пример #1
0
void *
PL_get_dbref(term_t t, db_ref_type *type_ptr)
{ void *data;
  PL_blob_t *type;

  if ( !PL_get_blob(t, &data, NULL, &type) )
  { error:
    PL_error(NULL, 0, NULL, ERR_TYPE, ATOM_db_reference, t);
    return NULL;
  }

  if ( type == &clause_blob )
  { clref *ref = data;

    if ( false(ref->clause, CL_ERASED) )
    { *type_ptr = DB_REF_CLAUSE;
      return ref->clause;
    }
  } else if ( type == &record_blob )
  { recref *ref = data;

    if ( ref->record->record &&
	 false(ref->record->record, R_ERASED) )
    { *type_ptr = DB_REF_RECORD;
      return ref->record;
    }
  } else
  { goto error;
  }

  return NULL;
}
Пример #2
0
static Code
undefSupervisor(Definition def)
{ if ( def->impl.clauses.number_of_clauses == 0 && false(def, PROC_DEFINED) )
    return SUPERVISOR(undef);

  return NULL;
}
Пример #3
0
main()       //主函数
{
    int k;
    double x, func(double);
    k = false(1.0, 3.0, 0.000001, func, &x);   //执行试位法
    printf("迭代次数 = %d\n", k);
    printf("一个实根为:%13.6e\n", x);
}
Пример #4
0
int
createForeignSupervisor(Definition def, Func f)
{ assert(true(def, P_FOREIGN));

  if ( false(def, P_VARARG) )
  { if ( def->functor->arity > MAX_FLI_ARGS )
      sysError("Too many arguments to foreign function %s (>%d)", \
	       predicateName(def), MAX_FLI_ARGS); \
  }

  if ( false(def, P_NONDET) )
  { Code codes = allocCodes(4);

    codes[0] = encode(I_FOPEN);
    if ( true(def, P_VARARG) )
      codes[1] = encode(I_FCALLDETVA);
    else
      codes[1] = encode(I_FCALLDET0+def->functor->arity);
    codes[2] = (code)f;
    codes[3] = encode(I_FEXITDET);

    def->codes = codes;
  } else
  { Code codes = allocCodes(5);

    codes[0] = encode(I_FOPENNDET);
    if ( true(def, P_VARARG) )
      codes[1] = encode(I_FCALLNDETVA);
    else
      codes[1] = encode(I_FCALLNDET0+def->functor->arity);
    codes[2] = (code)f;
    codes[3] = encode(I_FEXITNDET);
    codes[4] = encode(I_FREDO);

    def->codes = codes;
  }

#ifdef O_PROF_PENTIUM
  assert(prof_foreign_index < MAXPROF);
  def->prof_index = prof_foreign_index++;
  def->prof_name  = strdup(predicateName(def));
#endif

  succeed;
}
Пример #5
0
int
createUndefSupervisor(Definition def)
{ if ( def->number_of_clauses == 0 && false(def, PROC_DEFINED) )
  { def->codes = SUPERVISOR(undef);

    succeed;
  }

  fail;
}
Пример #6
0
int
PL_get_recref(term_t t, RecordRef *rec)
{ struct recref *ref;
  PL_blob_t *type;

  if ( !PL_get_blob(t, (void**)&ref, NULL, &type) ||
       type != &record_blob )
    return PL_error(NULL, 0, NULL, ERR_TYPE, ATOM_db_reference, t);

  if ( ref->record->record &&
       false(ref->record->record, R_ERASED) )
  { *rec = ref->record;
    return TRUE;
  }

  return FALSE;
}
Пример #7
0
bool Sphere::intersect(Ray &ray, Hit *hit)
{
	Vector ro;



	//this->transform.push(Translate(Vector(0, 5, 4)).m);
	//this->transformInv.push(Translate(Vector(0, 5, 4)).mInv);
	//this->transform.push(Scale(2, 1, 1).m);
	//this->transformInv.push(Scale(2, 1, 1).mInv);
	// ** Transformations ** // 
	//Matrix tr;

	////Transform trans = Translate(Vector(0, 0, 4));
	//Transform trans = Translate(Vector(3, 0, 0));
	////Transform scal = Scale(2, 1, 1);
	///*Transform rot = RotateZ(60);*/

	//tr = trans.mInv;
	//transformInvt = transformInv;
	//if(!transformInv.empty())
	//{
	//	ray.P = transformInv.top() * ray.P;
	//	ray.D = transformInv.top() * ray.D;
	//	//transformInv.pop();
	//}

	//ray.P = transfinalInv * ray.P;
	//ray.D = transfinalInv * ray.D;

	// *************************** //

	// offset ray by sphere position
	// equivalent to transforming ray into local sphere space

	Vector deltap;
	deltap = Vector(ray.P.x - sp.x, ray.P.y - sp.y, ray.P.z - sp.z);
	double a = ray.D.dot(ray.D);
	double b = deltap.dot(ray.D) * 2;
	double c = deltap.dot(deltap) - (r * r);

	double disc = b * b - 4 * a * c;
	if (disc < 0) {
		return false; // No intersection.
	}

	disc = sqrt(disc);

	double q;
	if (b < 0) {
		q = (-b - disc) * 0.5;
	}
	else {
		q = (-b + disc) * 0.5;
	}

	double r1 = q / a;
	double r2 = c / q;

	if (r1 > r2) {
		double tmp = r1;
		r1 = r2;
		r2 = tmp;
	}

	double distance = r1;
	if (distance < 0) {
		distance = r2;
	}

	if (distance < 0 || isnan(distance)) {
		return false(); // No intersection.
	}

	//// if an intersection has been found, record details in hit object

	hit->obj = this;

	hit->t = distance;

	hit->p.x = ray.P.x + distance * ray.D.x;
	hit->p.y = ray.P.y + distance * ray.D.y;
	hit->p.z = ray.P.z + distance * ray.D.z;
	hit->p.w = 1.0;
	hit->n.x = hit->p.x - sp.x;
	hit->n.y = hit->p.y - sp.y;
	hit->n.z = hit->p.z - sp.z;
	hit->n.normalise();
	return true;



}
int demo_test_fail()
{
	tf_assert(false(), "This demo_test should fail and emit this message to the log file");
	tf_passed();
}