glib-aux: move nm_utils_exp10() from core to libnm-glib-aux

This commit is contained in:
Thomas Haller 2021-03-02 21:07:12 +01:00
parent 9c32ba1910
commit b3f5113503
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
4 changed files with 35 additions and 33 deletions

View file

@ -156,37 +156,6 @@ _nm_singleton_instance_register_destruction(GObject *instance)
/*****************************************************************************/
static double
_exp10(guint16 ex)
{
double v;
if (ex == 0)
return 1.0;
v = _exp10(ex / 2);
v = v * v;
if (ex % 2)
v *= 10;
return v;
}
/*
* nm_utils_exp10:
* @ex: the exponent
*
* Returns: 10^ex, or pow(10, ex), or exp10(ex).
*/
double
nm_utils_exp10(gint16 ex)
{
if (ex >= 0)
return _exp10(ex);
return 1.0 / _exp10(-((gint32) ex));
}
/*****************************************************************************/
gboolean
nm_ether_addr_is_valid(const NMEtherAddr *addr)
{

View file

@ -185,8 +185,6 @@ nm_hash_update_in6addr_prefix(NMHashState *h, const struct in6_addr *addr, guint
nm_hash_update_in6addr(h, &a);
}
double nm_utils_exp10(gint16 e);
/**
* nm_utils_ip6_route_metric_normalize:
* @metric: the route metric

View file

@ -5708,3 +5708,34 @@ nm_utils_name_to_uid(const char *name, uid_t *out_uid)
buf = buf_heap;
}
}
/*****************************************************************************/
static double
_exp10(guint16 ex)
{
double v;
if (ex == 0)
return 1.0;
v = _exp10(ex / 2);
v = v * v;
if (ex % 2)
v *= 10;
return v;
}
/*
* nm_utils_exp10:
* @ex: the exponent
*
* Returns: 10^ex, or pow(10, ex), or exp10(ex).
*/
double
nm_utils_exp10(gint16 ex)
{
if (ex >= 0)
return _exp10(ex);
return 1.0 / _exp10(-((gint32) ex));
}

View file

@ -2491,4 +2491,8 @@ gboolean nm_utils_is_specific_hostname(const char *name);
char * nm_utils_uid_to_name(uid_t uid);
gboolean nm_utils_name_to_uid(const char *name, uid_t *out_uid);
/*****************************************************************************/
double nm_utils_exp10(gint16 e);
#endif /* __NM_SHARED_UTILS_H__ */