From 057de1f8454ccde4ff49796dc0bb43478055cec1 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sun, 4 Dec 2005 09:57:11 +0000 Subject: [PATCH] add tests that seem to show that the guint64/gdouble conversions are correct. Original commit message from CVS: * gst/gstutils.c: (gst_util_guint64_to_gdouble), (gst_util_gdouble_to_guint64), (gst_util_uint64_scale_int64): * gst/gstutils.h: * tests/check/gst/gstutils.c: (GST_START_TEST), (gst_utils_suite): add tests that seem to show that the guint64/gdouble conversions are correct. --- ChangeLog | 9 +++++++++ gst/gstutils.c | 26 ++++++++++++-------------- gst/gstutils.h | 28 ++++++++++++++++++++++++---- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index eba99845ca..ecf7894e3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-12-04 Thomas Vander Stichele + + * gst/gstutils.c: (gst_util_guint64_to_gdouble), + (gst_util_gdouble_to_guint64), (gst_util_uint64_scale_int64): + * gst/gstutils.h: + * tests/check/gst/gstutils.c: (GST_START_TEST), (gst_utils_suite): + add tests that seem to show that the guint64/gdouble conversions + are correct. + 2005-12-02 Wim Taymans * gst/gstregistry.c: (gst_registry_add_path): diff --git a/gst/gstutils.c b/gst/gstutils.c index bc1c66f8ba..faa87de44b 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -297,40 +297,40 @@ gst_util_set_object_arg (GObject * object, const gchar * name, } } -#ifdef WIN32 /* work around error C2520: conversion from unsigned __int64 to double * not implemented, use signed __int64 */ + /** - * gst_guint64_to_gdouble: - * @value: the value to convert + * gst_util_guint64_to_gdouble: + * @value: the #guint64 value to convert * * Convert @value to a gdouble. This is implemented as a function * because on some platforms a 64bit int to double conversion is * not defined/implemented. * - * Returns: @value converted to a double. + * Returns: @value converted to a #gdouble. */ gdouble -gst_guint64_to_gdouble (guint64 value) +gst_util_guint64_to_gdouble (guint64 value) { - if (value & 0x8000000000000000) + if (value & G_GINT64_CONSTANT (0x8000000000000000)) return (gdouble) ((gint64) value) + (gdouble) 18446744073709551616.; else return (gdouble) ((gint64) value); } /** - * gst_gdouble_to_guint64: - * @value: the value to convert + * gst_util_gdouble_to_guint64: + * @value: the #gdouble value to convert * * Convert @value to a guint64. This is implemented as a function * because on some platforms a double to guint64 conversion is not * defined/implemented. * - * Returns: @value converted to a double. + * Returns: @value converted to a #guint64. */ guint64 -gst_gdouble_to_guint64 (gdouble value) +gst_util_gdouble_to_guint64 (gdouble value) { if (value < (gdouble) 9223372036854775808.) /* 1 << 63 */ return ((guint64) ((gint64) value)); @@ -338,10 +338,8 @@ gst_gdouble_to_guint64 (gdouble value) value -= (gdouble) 18446744073709551616.; return ((guint64) ((gint64) value)); } -#endif - -/* convenience struct for getting high an low uint32 parts of +/* convenience struct for getting high and low uint32 parts of * a guint64 */ typedef union { @@ -434,7 +432,7 @@ gst_util_uint64_scale_int64 (guint64 val, guint64 num, guint64 denom) v.ll = val; n.ll = num; - /* do 128 bits multiply + /* do 128 bits multiply * nh nl * * vh vl * ---------- diff --git a/gst/gstutils.h b/gst/gstutils.h index 5c7045de99..3a75c9e144 100644 --- a/gst/gstutils.h +++ b/gst/gstutils.h @@ -33,12 +33,32 @@ void gst_util_set_value_from_string (GValue *value, const gchar *value_str); void gst_util_set_object_arg (GObject *object, const gchar *name, const gchar *value); void gst_util_dump_mem (const guchar *mem, guint size); +guint64 gst_util_gdouble_to_guint64 (gdouble value); +gdouble gst_util_guint64_to_gdouble (guint64 value); + +/** + * gst_guint64_to_gdouble: + * @value: the #guint64 value to convert + * + * Convert @value to a gdouble. + * + * Returns: @value converted to a #gdouble. + */ + +/** + * gst_gdouble_to_guint64: + * @value: the #gdouble value to convert + * + * Convert @value to a guint64. + * + * Returns: @value converted to a #guint64. + */ #ifdef WIN32 -guint64 gst_gdouble_to_guint64 (gdouble value); -gdouble gst_guint64_to_gdouble (guint64 value); +#define gst_gdouble_to_guint64(v) gst_util_gdouble_to_guint64(v) +#define gst_guint64_to_gdouble(v) gst_util_guint64_to_gdouble(v) #else -#define gst_gdouble_to_guint64(value) ((guint64) (value)) -#define gst_guint64_to_gdouble(value) ((gdouble) (value)) +#define gst_gdouble_to_guint64(value) ((guint64) (value)) +#define gst_guint64_to_gdouble(value) ((gdouble) (value)) #endif guint64 gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom);