You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
inlinedeffromFloatingDigits[T](givenx:FromDigits.Floating[T]): x.type= x
126
126
```
127
127
128
-
If a numeric literal has a known expected type `T` that is not one of the primitive numeric types, then the compiler will search for a given instance of `FromDigits[T]`. If one exists, then the compiler expands the literal to a call on the `fromDigits` method on the result obtained from calling one of the above four methods.
128
+
If a numeric literal has a concrete expected type `T` that is not one of the primitive numeric types, the compiler will search for a given instance of `FromDigits[T]`. If one exists, then the compiler will replace the numeric literal with an application of its digits to the `fromDigits` method on the result of the application of `T` to one of the above four methods, resulting in the following:
129
+
130
+
-`fromDigits[T].fromDigits(digits)` if the literal forms a whole number with base-10.
131
+
-`fromRadixDigits[T].fromDigits(digits, 16)` if the literal forms a whole number with base-16.
132
+
-`fromDecimalDigits[T].fromDigits(digits)` if the literal is base-10 with a single decimal point.
133
+
-`fromFloatingDigits[T].fromDigits(digits)` if the literal is base-10 with an exponent and optionally a single decimal point.
134
+
135
+
<!-- on the `fromDigits` method on the result obtained from calling one of the -->
129
136
130
137
As an example, the literal below has a nonsensical expected type `BigDecimal`, which can not be constructed with hex digits:
131
138
```scala
132
-
0xCAFEBABE:BigDecimal
139
+
0xABC_123:BigDecimal
133
140
```
134
-
Upon the compiler finding a given instance for `FromDigits[BigDecimal]`, the hex literal above expands to the following:
141
+
Upon the compiler finding a given instance for `FromDigits[BigDecimal]`, the hex literal above expands to the following, after removing numeric separators:
The given clause of `fromRadixDigits` asserts that the prior found `FromDigits` instance is a subtype of `FromDigits.WithRadix[BigDecimal]`, or else following error is issued:
139
146
```scala
140
-
1|0xCAFEBABE:BigDecimal
147
+
1|0xABC_123:BigDecimal
141
148
|^
142
149
|TypeBigDecimal does not have a FromDigits instance for whole numbers with radix other than 10.
0 commit comments