Skip to content

Commit 17af553

Browse files
authored
Add serialization proposal
1 parent da9377b commit 17af553

File tree

1 file changed

+86
-3
lines changed

1 file changed

+86
-3
lines changed

exploration/number-selection.md

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,92 @@ and they _might_ converge on some overlap that users could safely use across pla
548548
549549
### Standardize the Serialization Forms
550550
551-
Using the design above, remove the integer-only and no-sig-digits restrictions from LDML45
552-
and specify numeric matching by specifying the form of matching `key` values.
553-
Comparison is as-if by string comparison of the serialized forms, just as in LDML45.
551+
Modify the above exact match as follows.
552+
Note that this implementation is less restrictive than before, but still leaves some
553+
values that cannot be matched.
554+
555+
> [!IMPORTANT]
556+
> The exact behavior of exact literal match is only defined for
557+
> a specific range of numeric values and does not support scientific notation.
558+
> Very large or very small numeric values will be difficult to perform
559+
> exact matching on.
560+
> Avoid depending on these types of keys in message selection.
561+
562+
> [!IMPORTANT]
563+
> For implementations that do not have arbitrary precision numeric types
564+
> or operands that do not use these types,
565+
> it is possible to specify a key value that exceeds the precision
566+
> of the underlying type.
567+
> Such a key value will not work reliably or may not work at all
568+
> in such implementations.
569+
> Avoid depending on such keys values in message selection.
570+
571+
Number literals in the MessageFormat 2 syntax use a subset of the
572+
[format defined for a JSON number](https://www.rfc-editor.org/rfc/rfc8259#section-6).
573+
The resolved value of an `operand` exactly matches a numeric literal `key`
574+
if, when the `operand` is serialized using this format
575+
the two strings are equal.
576+
577+
```abnf
578+
number = [ "-" ] int [ fraction ]
579+
integer = "0" / [ "-" ] (digit19 *DIGIT)
580+
int = "0" / (digit19 *DIGIT)
581+
digit19 = %31-39 ; 1-9
582+
fraction = "." 1*DIGIT
583+
```
584+
585+
If the function `:integer` is used or the `maximumFractionDigits` is 0,
586+
the production `integer` is used and any fractional amount is omitted,
587+
otherwise the `minimumFractionDigits` number of digits is produced,
588+
zero-filled as needed.
589+
590+
The implementation applies the `maximumSignificantDigits` to the value
591+
being serialized.
592+
This might involve locally-specific rounding.
593+
The `minimumSignificantDigits` has no effect on the value produced for comparison.
594+
595+
The option `signDisplay` has no effect on the value produced for comparison.
596+
597+
> [!NOTE]
598+
> Implementations are not expected to implement this exactly as written,
599+
> as there are clearly optimizations that can be applied.
600+
601+
> Here are some examples:
602+
> ```
603+
> .input {$num :integer}
604+
> .match $num
605+
> 0 {{The number 0}}
606+
> 1 {{The number 1}}
607+
> -1 {{The number -1}}
608+
> 1.0 {{This cannot match}}
609+
> 1.1 {{This cannot match}}
610+
> ```
611+
> ```
612+
> .input {$num :number maximumFractionDigits=2 minimumFractionDigits=2}
613+
> .match $num
614+
> 0 {{This does not match}}
615+
> 0.00 {{This matches the value 0}}
616+
> 0.0 {{This does not match}}
617+
> 0.000 {{This does not match}}
618+
> ```
619+
> ```
620+
> .input {$num :number minimumFractionDigits=2 maximumFractionDigits=5}
621+
> .match $num
622+
> 0.12 {{Matches the value 0.12}
623+
> 0.123 {{Matches the value 0.123}}
624+
> 0.12345 {{Matches the values 0.12345}}
625+
> 0.123456 {{Does not match}}
626+
> 0.12346 {{May match the value 0.123456 depending on local rounding mode?}}
627+
> ```
628+
> ```
629+
> .input {$num :number}
630+
> -0 {{Error: Bad Variant Key}}
631+
> -99 {{The value -99}}
632+
> 1111111111111111111111111111 {{Might exceed the size of local integer type, but is valid}}
633+
> 11111111111111.1111111111111 {{Might exceed local floating point precision, but is valid}}
634+
> 1.23e-37 {{Error: Bad Variant Key}}
635+
> ```
636+
554637
555638
### Compare numeric values
556639

0 commit comments

Comments
 (0)