Ejemplo n.º 1
0
void test_gdouble_to_guint64()
{ 
  
  gdouble from[] = { 0., 1., 100., 10000., 9223372036854775808.,
    9223372036854775809., 13835058055282163712.
  };
  guint64 to[] = { 0, 1, 100, 10000, (guint64) (1) << 63,
    ((guint64) (1) << 63) + 1,
    ((guint64) (1) << 63) + (G_GINT64_CONSTANT (1) << 62)
  };
  guint64 tolerance[] = { 0, 0, 0, 0, 0, 1, 1 };
  gint i;
  gdouble result;
  guint64 delta;
  
  xmlfile = "gstutils_test_gdouble_to_guint64";
    std_log(LOG_FILENAME_LINE, "Test Started gstutils_test_gdouble_to_guint64");

  for (i = 0; i < G_N_ELEMENTS (from); ++i) {
    result = gst_util_gdouble_to_guint64 (from[i]);
    delta = ABS (to[i] - result);
    fail_unless (delta <= tolerance[i],
        "Could not convert %f: %" G_GUINT64_FORMAT
        " -> %d, got %d instead, delta of %e with tolerance of %e",
        i, from[i], to[i], result, delta, tolerance[i]);
  }
  std_log(LOG_FILENAME_LINE, "Test Successful");
  create_xml(0);
}
static GstClockTime
get_seconds (const GstRTSPTime * t)
{
  if (t->seconds < G_MAXINT) {
    gint num, denom;
    /* Don't do direct multiply with GST_SECOND to avoid rounding
     * errors.
     * This only works for "small" numbers, because num is limited to 32-bit
     */
    gst_util_double_to_fraction (t->seconds, &num, &denom);
    return gst_util_uint64_scale_int (GST_SECOND, num, denom);
  } else {
    return gst_util_gdouble_to_guint64 (t->seconds * GST_SECOND);
  }
}