aboutsummaryrefslogtreecommitdiffstats
path: root/src/decimal.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-10-06 20:40:56 +0200
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:59 +0100
commit9e59a63d9b5897d9ff6d0d9936a57c3167ea9a34 (patch)
treef54ecb581bef3e8476725e989b36e14ac556e0a2 /src/decimal.h
parent5a0d9e5a66e0ad0b85db3740b479301128637ad5 (diff)
downloadserd-9e59a63d9b5897d9ff6d0d9936a57c3167ea9a34.tar.gz
serd-9e59a63d9b5897d9ff6d0d9936a57c3167ea9a34.tar.bz2
serd-9e59a63d9b5897d9ff6d0d9936a57c3167ea9a34.zip
Add precise decimal digit generation
Diffstat (limited to 'src/decimal.h')
-rw-r--r--src/decimal.h20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/decimal.h b/src/decimal.h
index eefc07ef..8575cd85 100644
--- a/src/decimal.h
+++ b/src/decimal.h
@@ -19,14 +19,26 @@
#include <stdint.h>
+typedef struct {
+ unsigned count; ///< Number of digits
+ int expt; ///< Power of 10 exponent
+} SerdDecimalCount;
+
/// Return the number of decimal digits required to represent `n`
int
serd_count_digits(uint64_t i);
-unsigned
-serd_double_int_digits(double abs);
+/**
+ Write significant decimal digits for `d` into `buf`.
+
+ Writes only significant digits, without any leading or trailing zeros. The
+ actual number is given by the exponent in the return value.
-unsigned
-serd_decimals(double d, char* buf, unsigned frac_digits);
+ @param d The number to convert to decimal, must be finite and non-zero.
+ @param buf The output buffer at least `max_digits` long.
+ @param max_digits The maximum number of digits to write.
+*/
+SerdDecimalCount
+serd_decimals(double d, char* buf, unsigned max_digits);
#endif // SERD_DECIMAL_H