From b24672bb03c30f5cb73f628362a97bb1b02d6818 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 6 Oct 2019 20:59:12 +0200 Subject: Add support for xsd:double and xsd:float These can be used to serialise a float or double in the shortest normalised form that can be read back in to the exact same floating point value. --- serd/serd.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'serd') diff --git a/serd/serd.h b/serd/serd.h index 9dbbffa0..5a6815f8 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -724,6 +724,36 @@ serd_new_decimal(double d, unsigned max_frac_digits, const SerdNode* datatype); +/** + Create a new node by serialising `d` into a normalised xsd:double string. + + The returned node will always be in normalised scientific notation, like + "1.23E4", except for NaN and negative/positive infinity, which are "NaN", + "-INF", and "INF", respectively. + + Uses the shortest possible representation that precisely describes `d`, + which has at most 17 significant digits (under 24 characters total). + + @param d Double value to serialise. + @return A literal node with datatype xsd:double. +*/ +SERD_API +SerdNode* +serd_new_double(double d); + +/** + Create a new node by serialising `f` into a normalised xsd:float string. + + Uses identical formatting to serd_new_double(), except with at most 9 + significant digits (under 14 characters total). + + @param f Float value to serialise. + @return A literal node with datatype xsd:float. +*/ +SERD_API +SerdNode* +serd_new_float(float f); + /** Create a new node by serialising `i` into an xsd:integer string -- cgit v1.2.1