Returns true
if this MaybeDouble
is both valid and exact (has an
error
of 0.
Returns true
if this MaybeDouble
is both valid and exact (has an
error
of 0.0).
Sometimes a number is too large to fit in a Double
, the result of an
operation cannot be computed (eg.
Sometimes a number is too large to fit in a Double
, the result of an
operation cannot be computed (eg. sqrt of a negative number), other times
we just give up when trying to keep track of the error... In any case, the
approx
is set to either NaN
or an Infinity
, and it will be marked
as invalid. In that case, this will return false
otherwise it will
return true
.
This implements the modulus operator.
This implements the modulus operator. It will behave similar to % for Double, Long, Int, etc.
FIXME: Implement arbitrary nroots w/ error bounds.
If this MaybeDouble
's sign can be computed exactly, then Some(x)
is
returned where x
is the Double
approximation.
If this MaybeDouble
's sign can be computed exactly, then Some(x)
is
returned where x
is the Double
approximation. Otherwise, None
is
returned.
Currently, if this can't be answered exactly, then the result is made invalid.
Currently, if this can't be answered exactly, then the result is made invalid. This should be fixed. If the answer is exact, then it is returned with a 0 error bound.
If this MaybeDouble
's sign can be computed exactly, then Some(s)
is
returned, where s
is the sign of the number.
If this MaybeDouble
's sign can be computed exactly, then Some(s)
is
returned, where s
is the sign of the number. Otherwise, None
is
returned.
Returns Some(f)
, where f
is a Float
, if f
is known to be exact.
Returns Some(f)
, where f
is a Float
, if f
is known to be exact.
Otherwise, returns None
.
If this can be converted, exactly, into a Long
, then Some(n)
will be
returned, where n
is a Long
.
If this can be converted, exactly, into a Long
, then Some(n)
will be
returned, where n
is a Long
. Otherwise, None
will be returned.
A
MaybeDouble
will hold aDouble
approximation so long as theDouble
's sign can be computed exactly. It is not a general number type, but is meant to be used in tandem with a more accurate, but slow (computationally), number type. When performing comparisons then, this can be checked first to save on potentially slow computation.For this type, if a method returns an
Option
al value, then that indicates that ifNone
is returned, the answer cannot be computed exactly, but ifSome(x)
is returned, then that is guaranteed to be correct. For example,toLong
,toFloat
,sign
,isWhole
, etc. return these types of optional, only-if-correct, type values.Most likely you would not use this directly, but just wrap your number type in a
FPFilter
which maintains aMaybeDouble
and handles all the lazy computation of the more accurate number type for you.