[Haskell-cafe] ANN: logfloat

wren ng thornton wren at freegeek.org
Fri Apr 3 18:51:39 EDT 2009

-- logfloat

This package provides a type for storing numbers in the log-domain, 
primarily useful for preventing underflow when multiplying many 
probabilities as in HMMs and other probabilistic models. The package 
also provides modules for dealing with floating numbers correctly.

-- Now using FFI

We now use the FFI to gain access to C's accurate log1p (and expm1) 
functions. This greatly increases the range of resolution, especially 
for very small LogFloat values. These are currently exposed from 
Data.Number.LogFloat, though they may move to a different module in 
future versions.

On GHC 6.10 the use of -fvia-C had to be disabled because it conflicts 
with the FFI (version still used it, which is fine on GHC 6.8). 
I'm still investigating the use of -fasm and getting proper benchmarking 
numbers. Contact me if you notice significant performance degradation.

Using the FFI complicates the build process for Hugs; details are noted 
in the INSTALL file. It may also complicate building on Windows (due to 
ccall vs stdcall), though I'm not familiar with Windows FFI and don't 
have a machine to test on.

The calling convention is "unsafe" in order to avoid overhead. However, 
in the past this has been noted to cause issues with multithreaded 
applications since it locks all RTS threads instead of just the calling 
thread. If you're using logfloat in a multithreaded application and 
notice a slowdown, or if you're more familiar with these details than I, 
tell me so I can fix things.

If you have any difficulties with the FFI, let me know. As an interim 
solution the FFI can be disabled by turning off the useFFI Cabal flag 
during configure, which will compile the package to use the naive log1p 
implementation from earlier versions.

-- Other changes since 0.11.0

* (0.11.1) Felipe Lessa added an instance for IArray UArray LogFloat. On 
GHC we use newtype deriving; On Hugs we fall back to unsafeCoerce to 
distribute the newtype over IArray UArray Double.

* (0.11.2 Darcs) Moved the log/exp fusion rules from 
Data.Number.LogFloat into Data.Number.Transfinite where our log function 
is defined.

* Added a Storable LogFloat instance for GHC. No implementation is 
available yet for Hugs.

* Removed orphaned toRational/fromRational fusion rules, which were 
obviated by the introduction of the Data.Number.RealToFrac module in 0.11.0.

* Changed the Real LogFloat instance to throw errors when trying to 
convert transfinite values into Rational.

-- Compatibility / Portability

The package is compatible with Hugs (September 2006) and GHC (6.8, 
6.10). For anyone still using GHC 6.6, the code may still work if you 
replace LANGUAGE pragma by equivalent OPTIONS_GHC pragma.

The package is not compatible with nhc98 and Yhc because 
Data.Number.RealToFrac uses MPTCs. The other modules should be compatible.

-- Links




Haddock (Darcs version):

Live well,

More information about the Haskell-Cafe mailing list