Fabio Berta
04/19/2023, 7:55 PMCLOVIS
04/20/2023, 7:57 AMYoussef Shoaib [MOD]
04/20/2023, 3:22 PMNumberOps<N>
that defines arithmetic on type N
. N is constrained to N : Number, N : Comparable<N>
because Number provides (truncating/unsafe) conversions to Int/Float/etc, and Comparable provides comparisons between N values. Those properties could also just be part of the interface instead, which might make it easier to implement for more unusual types (like UInt, which doesn't extend Number). The reason why NumberOps doesn't have times
and divides
and instead FloatingPointOps has them is that, in the domain of the library, we only want those operations to work on floating point numbers so that they preserve (up to an epsilon because floating point isn't exact) properties like 1 / 2 * 2 == 1
and so each type that has a NumberFpOps
has a "carrier" floating point type FP
that it fits into perfectly, and thus all multiplication and division should happen on that type, before finally converting back to N
. This is quite domain-specific, and I can imagine that in your code you likely will just want to define all those operations, and so take the code linked above as guidance and not as gospel.Fabio Berta
04/20/2023, 9:30 PMYoussef Shoaib [MOD]
04/21/2023, 12:42 AM