GHC: Ticket Query
http://ghc.haskell.org/trac/ghc/query?status=!closed&reporter=malosh&order=priority
The Glasgow Haskell Compileren-USGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/query?status=!closed&reporter=malosh&order=priority
Trac 1.0.1
http://ghc.haskell.org/trac/ghc/ticket/4092
http://ghc.haskell.org/trac/ghc/ticket/4092#4092: Floating point manipulation : ulp and coerce IEEE-754 Double# into Word64#Mon, 24 May 2010 15:57:54 GMTmalosh<p>
There are currently two ways to compute the ulp of double numbers with GHC :
</p>
<ul><li>Calling a C function, which requires to allocate a pointer. This is way too expensive when using interval arithmetic (for instance), that compute two ULPs at each arithmetic operations.
</li><li>Programming it by hand in haskell with GHC primitive operations, which requires using unsafeCoerce# : this does not work in GHC 6.12.2.
</li></ul><p>
unsafeCoerce# should work, and there should be a primitive ulp# function in GHC, operating on Doubles at least.
By the way, here is my haskell code using C for computing it :
</p>
<pre class="wiki">foreign import ccall unsafe "math.h frexp" c_frexp::CDouble->(Ptr CInt)->IO ()
foreign import ccall unsafe "math.h ldexp" c_ldexp::CDouble->CInt->IO CDouble
ulp::Double->Double
ulp x=unsafePerformIO $ do
expon<-alloca (\e->do
c_frexp (realToFrac x) e
peek e)
(c_ldexp 0.5 $ expon-52) >>= return.realToFrac
</pre>Resultshttp://ghc.haskell.org/trac/ghc/ticket/4092#changelog
http://ghc.haskell.org/trac/ghc/ticket/4101
http://ghc.haskell.org/trac/ghc/ticket/4101#4101: Primitive constant unfoldingFri, 28 May 2010 13:50:50 GMTmalosh<p>
Examining the core generated by ghc with -O2 on a numerical code, I saw things like :
</p>
<pre class="wiki">case GHC.Prim.<## x_aB9 (GHC.Prim.**## 2.0 -1021.0) of _ {...
</pre><p>
This code being executed each time my code performs an addition ! GHC does not seem to unfold the constants right with at least <strong>##. By the way, it should definitely be possible to specify a Double# constant in hexadecimal.
</strong></p>
Resultshttp://ghc.haskell.org/trac/ghc/ticket/4101#changelog