Esempio n. 1
0
/**
 * Divide a GPS time by a number.  Computes gps / x and places the result
 * in gps.  Returns gps on success, NULL on failure.
 */
LIGOTimeGPS *XLALGPSDivide( LIGOTimeGPS *gps, REAL8 x )
{
  LIGOTimeGPS quotient;
  double residual;

  if(isnan(x)) {
    XLALPrintError("%s(): NaN", __func__);
    XLAL_ERROR_NULL(XLAL_EFPINVAL);
  }
  if(x == 0) {
    XLALPrintError("%s(): divide by zero", __func__);
    XLAL_ERROR_NULL(XLAL_EFPDIV0);
  }

  /* initial guess */
  if(!XLALGPSSetREAL8(&quotient, XLALGPSGetREAL8(gps) / x))
    XLAL_ERROR_NULL(XLAL_EFUNC);
  /* use Newton's method to iteratively solve for quotient.  strictly
   * speaking we're using Newton's method to solve for the inverse of
   * XLALGPSMultiply(), which we assume implements multiplication. */
  do {
    LIGOTimeGPS workspace = quotient;
    if(!XLALGPSMultiply(&workspace, x))
      XLAL_ERROR_NULL(XLAL_EFUNC);
    residual = XLALGPSDiff(gps, &workspace) / x;
    if(!XLALGPSAdd(&quotient, residual))
      XLAL_ERROR_NULL(XLAL_EFUNC);
  } while(fabs(residual) > 0.5e-9);
  *gps = quotient;

  return gps;
}
Esempio n. 2
0
static PyObject *__mul__(PyObject *self, PyObject *other)
{
	LIGOTimeGPS gps;
	double factor;

	if(pylal_LIGOTimeGPS_Check(self) && !pylal_LIGOTimeGPS_Check(other)) {
		gps = ((pylal_LIGOTimeGPS *) self)->gps;
		factor = PyFloat_AsDouble(other);
	} else if(!pylal_LIGOTimeGPS_Check(self) && pylal_LIGOTimeGPS_Check(other)) {
		gps = ((pylal_LIGOTimeGPS *) other)->gps;
		factor = PyFloat_AsDouble(self);
	} else {
		Py_INCREF(Py_NotImplemented);
		return Py_NotImplemented;
	}
	if(PyErr_Occurred())
		return NULL;

	XLALGPSMultiply(&gps, factor);

	return pylal_LIGOTimeGPS_new(gps);
}