glib: Add explicit casts for some double → other numeric type conversions

If we enable `-Wfloat-conversion`, these warn about a possible loss of
precision due to an implicit conversion from `double` to some other
numeric type.

The warning is correct: there is a possible loss of precision here. In
these instances, we don’t care, as the floating point arithmetic is
being done to do some imprecise scaling or imprecise timing. A loss of
precision is not a problem.

So, add an explicit cast to squash the warning.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
This commit is contained in:
Philip Withnall 2024-06-28 14:22:13 +01:00
parent ad5948bbf5
commit 2713255574
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73
4 changed files with 7 additions and 7 deletions

View File

@ -1537,7 +1537,7 @@ g_task_thread_setup (void)
if (tasks_running == G_TASK_POOL_SIZE)
task_wait_time = G_TASK_WAIT_TIME_BASE;
else if (tasks_running > G_TASK_POOL_SIZE && tasks_running < G_TASK_WAIT_TIME_MAX_POOL_SIZE)
task_wait_time *= G_TASK_WAIT_TIME_MULTIPLIER;
task_wait_time = (guint64) (task_wait_time * G_TASK_WAIT_TIME_MULTIPLIER);
if (tasks_running >= G_TASK_POOL_SIZE)
g_source_set_ready_time (task_pool_manager, g_get_monotonic_time () + task_wait_time);
@ -1562,7 +1562,7 @@ g_task_thread_cleanup (void)
g_source_set_ready_time (task_pool_manager, -1);
if (tasks_running > G_TASK_POOL_SIZE && tasks_running < G_TASK_WAIT_TIME_MAX_POOL_SIZE)
task_wait_time /= G_TASK_WAIT_TIME_MULTIPLIER;
task_wait_time = (guint64) (task_wait_time / G_TASK_WAIT_TIME_MULTIPLIER);
tasks_running--;

View File

@ -1670,7 +1670,7 @@ g_date_time_new (GTimeZone *tz,
* is 1000000. This is not a problem with precision, it's just how
* FP numbers work.
* See https://bugzilla.gnome.org/show_bug.cgi?id=697715. */
usec = seconds * USEC_PER_SECOND;
usec = (gint64) (seconds * USEC_PER_SECOND);
usecd = (usec + 1) * 1e-6;
if (usecd <= seconds) {
usec++;
@ -1973,7 +1973,7 @@ GDateTime*
g_date_time_add_seconds (GDateTime *datetime,
gdouble seconds)
{
return g_date_time_add (datetime, seconds * USEC_PER_SECOND);
return g_date_time_add (datetime, (GTimeSpan) (seconds * USEC_PER_SECOND));
}
/**

View File

@ -813,7 +813,7 @@ g_hash_table_resize (GHashTable *hash_table)
* Immediately after growing, the load factor will be in the range
* .375 .. .469. After shrinking, it will be exactly .5. */
g_hash_table_set_shift_from_size (hash_table, hash_table->nnodes * 1.333);
g_hash_table_set_shift_from_size (hash_table, (gint) (hash_table->nnodes * 1.333));
if (hash_table->size > old_size)
{

View File

@ -2703,7 +2703,7 @@ g_uri_escape_string (const gchar *unescaped,
g_return_val_if_fail (unescaped != NULL, NULL);
s = g_string_sized_new (strlen (unescaped) * 1.25);
s = g_string_sized_new ((size_t) (strlen (unescaped) * 1.25));
g_string_append_uri_escaped (s, unescaped, reserved_chars_allowed, allow_utf8);
@ -2797,7 +2797,7 @@ g_uri_escape_bytes (const guint8 *unescaped,
g_return_val_if_fail (unescaped != NULL, NULL);
string = g_string_sized_new (length * 1.25);
string = g_string_sized_new ((size_t) (length * 1.25));
_uri_encoder (string, unescaped, length,
reserved_chars_allowed, FALSE);