An integer that remembers the base it is written in.
The fourth sibling of _Number, after _Complex, _Truth and _Rational, and built to the same pattern: a private constructor behind a smart factory, and a value that is read as a number through _Number's widening extractor so no existing case _Number(x) site has to learn about it.
Why the base lives on the value. A base conversion that returns bare digits is only a decomposition: [[15, 15]] is indistinguishable from a matrix typed by hand, and the caller has to remember the base to reassemble it. Putting the base on the value is what makes A := 0xFF still be FF when it is printed an hour later.
The tag is shallow, deliberately. 0xFF + 1 prints 256 in decimal, because Sum.eval reads both operands as numbers and builds a plain _Number. Carrying the base through arithmetic would require deciding whose base wins in 0xFF + 0b1011, and there is no defensible answer — so the base survives display and storage, which is what a base is for, and arithmetic falls back to decimal.
In exact mode the value is exact too (F_0323, LT L_0080): a literal parsed or a tobase taken under exact on carries its integer, _Rational.containsExact reports it, and the operators read it through _Based.unwrapExact -- so 0b1010 + 0b0110 is the exact 16, not 16.0 with a note, and :save groups the value under exact on. Outside exact mode nothing changes. A fourth field on a case class with a private constructor is additive: in Scala 3 unapply returns the instance and copy is private with the constructor.
Value parameters
- balanced
-
whether the digits are the balanced set (base 3 only)
- base
-
the radix,
2 .. 36 - exact
-
the integer when the value is exact (F_0323), else
None - value
-
the integer value, held as a
Doublelike every other numeric tier
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait _Valuetrait _Expressionclass Objecttrait Matchableclass Any