aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/node.c11
-rw-r--r--src/serd_internal.h8
2 files changed, 9 insertions, 10 deletions
diff --git a/src/node.c b/src/node.c
index 921b05de..6b35dd79 100644
--- a/src/node.c
+++ b/src/node.c
@@ -216,6 +216,13 @@ serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out)
return node;
}
+static inline unsigned
+serd_digits(double abs)
+{
+ const double lg = ceil(log10(abs + 1.0));
+ return lg < 1.0 ? 1U : (unsigned)lg;
+}
+
SERD_API
SerdNode
serd_node_new_decimal(double d, unsigned frac_digits)
@@ -225,7 +232,7 @@ serd_node_new_decimal(double d, unsigned frac_digits)
}
const double abs_d = fabs(d);
- const unsigned int_digits = (unsigned)fmax(1.0, ceil(log10(abs_d + 1)));
+ const unsigned int_digits = serd_digits(abs_d);
char* buf = (char*)calloc(int_digits + frac_digits + 3, 1);
SerdNode node = { (const uint8_t*)buf, 0, 0, 0, SERD_LITERAL };
const double int_part = floor(abs_d);
@@ -276,7 +283,7 @@ SerdNode
serd_node_new_integer(int64_t i)
{
int64_t abs_i = (i < 0) ? -i : i;
- const unsigned digits = fmax(1.0, ceil(log10((double)abs_i + 1)));
+ const unsigned digits = serd_digits(abs_i);
char* buf = (char*)calloc(digits + 2, 1);
SerdNode node = { (const uint8_t*)buf, 0, 0, 0, SERD_LITERAL };
diff --git a/src/serd_internal.h b/src/serd_internal.h
index d96d4969..20700bb8 100644
--- a/src/serd_internal.h
+++ b/src/serd_internal.h
@@ -38,14 +38,6 @@
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
-#ifndef HAVE_FMAX
-static inline double
-fmax(double a, double b)
-{
- return (a < b) ? b : a;
-}
-#endif
-
/* File and Buffer Utilities */
static inline FILE*