Since the normal
log throws an error on zero, we have to
redefine it in order for things to work right. Arguing from limits we
can see that
log 0 == negativeInfinity. Newer versions of GHC
have this behavior already, but older versions and Hugs do not.
This function will raise an error when taking the log of negative
numbers, rather than returning
notANumber as the newer GHC
implementation does. The reason being that typically this is a logical
error, and
notANumber allows the error to propagate silently.
In order to improve portability, the
Transfinite class is
required to indicate that the
Floating type does in fact have a
representation for negative infinity. Both native floating types
(
Double and
Float) are supported. If you define your own
instance of
Transfinite, verify the above equation holds for
your
0 and
negativeInfinity. If it doesn't, then you
should avoid importing our
log and will probably want
converters to handle the discrepancy.
For GHC, this version of
log has rules for fusion with
exp. These can give different behavior by preventing overflow
to
infinity and preventing errors for taking the logarithm of
negative values. For
Double and
Float they can also give
different answers due to eliminating floating point fuzz. The rules
strictly improve mathematical accuracy, however they should be noted
in case your code depends on the implementation details.