Section 22.4 “Using a typeclass”, page 484 has overflow examples, I put them into Scastie: Scastie - An interactive playground for Scala.
Which is correct? Could not find anything in the book’s Errata.
Possibly an error in the book?
So, for -Short.MinValue
and -Byte.MinValue
the overflows do not happen,
due to, I’m guessing, an implicit conversion to Int
.
But with Short.MinValue.abs
and Byte.MinValue.abs
the overflows DO happen.
Why? Why no conversion in that case? Probably because unary_-
is overloaded
differently than abs
?