@@ -46,7 +46,7 @@ The S-expression MUST be assembled as follows:
4646 slot.
4747 2 . Append to the S-expression ` (N:SLOTNAME ` , where _ SLOTNAME_ is the LinkML
4848 name for the slot and _ N_ is the length of the slot name (so, for
49- rxample , ` (10:subject_id ` , ` (9:author_id ` , ` (10:confidence ` , etc.).
49+ example , ` (10:subject_id ` , ` (9:author_id ` , ` (10:confidence ` , etc.).
5050 3 . If the slot is defined as a multi-valued slot (and even if it has only
5151 one value in the mapping record to hash):
5252 1 . Append ` ( ` .
@@ -55,9 +55,10 @@ The S-expression MUST be assembled as follows:
5555 length of _ V_ .
5656 3 . Append ` ) ` .
5757 4 . If the slot is typed as a floating point number (e.g. ` confidence ` ),
58- convert the value to a string _ V_ by truncating the floating point number
59- to up to 3 digits after the decimal point, rounding the last digit half
60- away from zero. Then append ` N:V ` , where _ N_ is the length of _ V_ .
58+ convert the value into a string _ V_ according to the rules set forth in
59+ the section
60+ [ Formatting floating-point values] ( #formatting-floating-point-values ) .
61+ Then append ` N:V ` , where _ N_ is the length of _ V_ .
6162 5 . If the slot is typed as an enumeration (e.g. ` subject_type ` ), append
6263 ` N:ENUMVALUE ` , where _ ENUMVALUE_ is the allowed value in the enumeration
6364 as specified in the LinkML model, and _ N_ is the length of _ ENUMVALUE_
@@ -90,7 +91,7 @@ Converting extension values to string:
9091| ----------------------- | ---------------------------------------------------------------------------------------------------------- |
9192| ` xsd:string ` | No conversion needed, use the value directly |
9293| ` xsd:integer ` | Base 10 representation of the integer value |
93- | ` xsd:double ` | Truncate the number to up to 3 digits after the decimal point, round the last digit half away from zero |
94+ | ` xsd:double ` | Apply the rules from the section [ Formatting floating-point values ] ( #formatting-floating- point-values ) |
9495| ` xsd:boolean ` | ` true ` or ` false ` |
9596| ` xsd:date ` | ISO-8601 representation: ` YYYY-MM-DD ` |
9697| ` xsd:datetime ` | ISO-8601 representation: ` YYYY-MM-DDThh:mm:ssTZ ` where ` TZ ` is the zone offset (e.g. ` +01:00 ` or ` -06:30 ` ) |
@@ -111,6 +112,34 @@ Encode the hash computed in step 2 into uppercase hexadecimal, also known as
111112Base16 encoding as defined in
112113[ RFC 4648] ( https://datatracker.ietf.org/doc/html/rfc4648#section-8 ) .
113114
115+ <a id =" formatting-floats " ></a >
116+
117+ ### Formatting floating-point values
118+
119+ Whenever a floating-point number needs to be appended to the canonical
120+ S-expression built in Step 2 above, the following specific rules apply:
121+
122+ 1 . The non-fractional part MUST NOT be omitted, even it is zero. For example,
123+ ` 0.7 ` MUST NOT be written as ` .7 ` .
124+ 2 . The fractional part MUST be truncated to _ up to_ 3 digits _ as needed_ . If the
125+ fractional part can be written in less than 3 digits, then it MUST NOT be
126+ right-padded with zeros. For example, ` 0.7 ` MUST NOT be written as ` 0.700 ` .
127+ 3 . If the fractional part needs to be truncated, the value MUST be rounded to
128+ the nearest value representable with 3 digits, rounding half away from zero.
129+ This corresponds to the _ roundTiesToAway_ mode as defined by [ IEEE 754-2019
130+ §4.3.1] (https://doi.org/ 10.1109/IEEESTD.2019.8766229).
131+
132+ The following table gives some examples of rounding after truncation:
133+
134+ | Original value | Canonical representation |
135+ | -------------- | ------------------------ |
136+ | 0.7832... | 0.783 |
137+ | 0.7835... | 0.784 |
138+ | 0.7836... | 0.784 |
139+ | -0.7832... | -0.783 |
140+ | -0.7836... | -0.784 |
141+ | -0.7835... | -0.784 |
142+
114143## Example
115144
116145> This section is not normative. It provides a step-by-step example of how to
0 commit comments