A simple type class for numeric types that are a subset of the reals.
This is a type class for types with n-roots.
A simple ADT representing the Sign
of an object.
A trait for things that have some notion of sign and the ability to ensure something has a non-negative sign.
This is a type class for types with n-roots.
For many types, the value returned by
nroot
andsqrt
are only guaranteed to be approximate answers. Thus, many (most?) instances of NRoot will not be able to ensure thatsqrt(x) * sqrt(x) = x
.Also, generally
nroot
s wheren
is even are not defined for negative numbers. The behaviour is undefined if this is attempted.It would be nice to ensure an exception is raised, but some types may defer computation and testing if a value is negative may not be ideal. So, do not count on
ArithmeticException
s to save you from bad arithmetic!