Here’s the documentation NumericRange It says
NumericRange is a more generic version of the
Range class which works with arbitrary types. It must be supplied with an
Integral implementation of the range type.
If we look at the source code here for
NumericRange scala/NumericRange.scala at v2.13.8 · scala/scala · GitHub we can see that
quot is used, which means it has to be provided. (Interestingly
rem is not used! At least not there. Probably used in other places that require
As you can see here from the initial part of the code
sealed class NumericRange[T](
val start: T,
val end: T,
val step: T,
val isInclusive: Boolean
an implicit value of type
Integral[T] must be present for it to work. Implicits of Scala 2 and typeclasses of Haskell (and of Scala 3) both implement the same idea: ad-hoc polymorphism.
So it’s not about a
BigDecimal itself being “integer-like”, it’s about the range-like functionality that needs an “integer-like” thing (the implicit value) to work. The
quot (and possibly the
rem) methods of the implicit value are used in the generation of ranges. If you don’t know/understand implicits or typeclasses this will be confusing for you.
If we keep reading the comments in the source code it says:
Factories for likely types include Range.BigInt, Range.Long, and Range.BigDecimal. Range.Int exists for completeness
Range functionality is made specially for
BigDecimal but not
Double. I’m sure there are some reasons for this.
But these are all technical implementation details that we shouldn’t worry about.
You really shouldn’t be thinking too much about this stuff. Especially if you are new to Scala. Just use it, you don’t need to understand how it’s implemented under the hood.
DO NOT waste your time trying to find answers to these kinds of questions on your own. Get the book Programming in Scala, Fifth Edition Resources which explains every type in detail. Or take the online classes Online Courses (MOOCs) from The Scala Center | Scala Documentation I see newcomers keep wasting so much time with web searches, StackOverflows, tutorials etc. Just go straight to the source made by the language creators.