Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

big update fixing many things #27

Merged
merged 64 commits into from
Nov 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
cc0d04f
bump dependencies
claudeha Jun 6, 2015
1e1bd68
silence cabal default-language warning
claudeha Jun 6, 2015
0c53a7d
bind to MPFR types using hsc2hs, with hgmp for GMP types
claudeha Jun 7, 2015
41ec435
remove unused TH extenrsion in Precision
claudeha Jun 7, 2015
240f3b8
rewrite bindings to use FFI instead of CMM wrappers
claudeha Jun 7, 2015
c5e5bd7
no longer needed cmm wrappers and constant extractor
claudeha Jun 7, 2015
0438873
cabal build type simple
claudeha Jun 7, 2015
117f0f3
remove unused dependencies
claudeha Jun 7, 2015
5445b72
document other-extensions in cabal file
claudeha Jun 7, 2015
a8ac258
tested with GHC 7.10.1
claudeha Jun 7, 2015
4f3d3fe
avoid pages of warnings about unticked promotions
claudeha Jun 7, 2015
83c2685
remove unused patched mpfr-3.1.2
claudeha Jun 7, 2015
30d9cca
use bracket
claudeha Mar 19, 2017
13a51d8
delete non-compiling, apparently unneeded SingKind instance
claudeha Mar 19, 2017
aea74c1
bump versions
claudeha Mar 19, 2017
d92ce4c
tested with ghc-8.0.2
claudeha Mar 19, 2017
50234b4
adapt to current hgmp
claudeha Mar 19, 2017
8b708af
ignore sandbox
claudeha Mar 19, 2017
c41b639
no longer contains patched copy
claudeha Mar 19, 2017
4f04120
add missing deps for examples
claudeha Mar 19, 2017
e20c153
add myself to copyright field
claudeha Mar 20, 2017
63b255a
tested with ghc-7.10.3
claudeha Mar 20, 2017
7b0b058
update copyright notice
claudeha Mar 20, 2017
cddc66a
examples extracted from cabal file and readme
claudeha Mar 20, 2017
0ff60bc
proper fromDouble implementation
claudeha Mar 20, 2017
8d68f8b
proper fromInt implementation
claudeha Mar 20, 2017
8776722
tweak FFI functionality
claudeha Mar 20, 2017
cdb17b6
proper alignment implementation
claudeha Mar 20, 2017
63aebf7
toDouble implementation
claudeha Mar 20, 2017
3f43a12
mostly non-working RULES pragmas for numeric conversion
claudeha Mar 20, 2017
2e902db
a few more tests, including one for RULES firing
claudeha Mar 20, 2017
de1a19b
helper function for sgn
claudeha Mar 21, 2017
974a5cd
faster show via mpfr_get_str
claudeha Mar 21, 2017
ed9e0de
module header for Types
claudeha Mar 21, 2017
f03a32c
update copyright in Rounded module
claudeha Mar 21, 2017
e34bc0a
still need an efficient properFraction
claudeha Mar 21, 2017
cbe2148
precRound implementation
claudeha Mar 21, 2017
e7711d7
note about non-shortest representation
claudeha Mar 21, 2017
2bab2bf
higher-rank peekRounded with reified precision
claudeha Mar 21, 2017
1600061
fix a couple of warnings
claudeha Mar 21, 2017
b39d825
documentation tweaks
claudeha Mar 21, 2017
daa8f97
log1p and expm1, guarded by CPP for older base
claudeha Mar 21, 2017
78312a3
fix a warning
claudeha Mar 21, 2017
9e93408
documentation tweaks
claudeha Mar 21, 2017
1de57b7
better properFraction implementation
claudeha Mar 21, 2017
7cfbafb
optimize round
claudeha Mar 21, 2017
a25950b
fromInteger small integer optimisation
claudeha Mar 21, 2017
d57702d
use less safe but faster version of withOutRounded
claudeha Mar 21, 2017
57f65a2
move fixme note to foreign import
claudeha Mar 21, 2017
25125c8
only show parens for negative values
claudeha Mar 21, 2017
834c60b
simple Read instance; likely to be slow
claudeha Mar 21, 2017
c8a11fc
rename FFI helpers and add some more
claudeha Mar 21, 2017
0bc0804
wrap some mpfr functions to handle exception flags safely; throw Over…
claudeha Mar 21, 2017
4e42e95
document rounding modes
claudeha Mar 21, 2017
7b888e4
relax dependencies
claudeha Aug 4, 2017
6551f7b
tested with ghc 8.2.1
claudeha Aug 4, 2017
e7e34ce
hsc2hs alignment macro for older GHC versions
claudeha Sep 11, 2017
27e4e0b
move foreign imports to separate file
claudeha Sep 11, 2017
d354857
'simple' interface with value-level rounding mode and precision
claudeha Sep 11, 2017
3144a77
bump hgmp min version to 0.1.1
claudeha Sep 12, 2017
9cc8e04
FFI helpers for Simple interface
claudeha Nov 14, 2017
c825715
Simple encodeFloat' takes a rounding mode
claudeha Nov 14, 2017
a4eebd0
add newline at end of file
claudeha Nov 14, 2017
df1608d
export precision from Simple
claudeha Nov 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ libtool
/deps/mpfr-*/src/mparam.h
deps/mpfr-3.1.2/autom4te.cache/
cabal.sandbox.config
.cabal-sandbox
6 changes: 3 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ rounded
[![Build Status](https://secure.travis-ci.org/ekmett/rounded.png?branch=master)](http://travis-ci.org/ekmett/rounded)

This package provides properly rounded floating point numbers of arbitrary precision.

It does so by wrapping the GNU MPFR library. However, it actually contains a patched copy of MPFR 3.1.0,
which has been updated to be compatible with GHC's use of GMP's garbage collection hook.
It does so by wrapping the GNU MPFR library.

Phantom types carry the information about the precision and rounding mode, letting you treat properly rounded floating
point numbers as instances of `Num` or `Floating`, like any other numeric type in Haskell.
Expand All @@ -19,7 +17,9 @@ Usage

```haskell
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Numeric.Rounded
import Data.Proxy
```

To use a 53 bit significand (the same size as used by a Double), and round down intermediate results:
Expand Down
201 changes: 1 addition & 200 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -1,201 +1,2 @@
module Main (main) where

import Distribution.Simple
import Distribution.Simple.Program
import Distribution.Simple.Program.Builtin
import Distribution.Simple.Program.Db
import Distribution.Simple.Program.Ar
import Distribution.Simple.Program.Find
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Setup
import Distribution.PackageDescription hiding (Flag)
import Distribution.Verbosity

import System.IO
import System.Process
import System.FilePath
import System.Directory
import System.Exit

import Control.Applicative
import Control.Monad

import Data.List
import Data.Monoid
import Data.Maybe

-----------------------------------------------------------------
-- Horrible mess of semi-general code
--

-- Not particularly thread safe, but the whole notion of a current directory isn't either
inDirectory :: FilePath -> IO r -> IO r
inDirectory dir action = do
old <- getCurrentDirectory
setCurrentDirectory dir
res <- action
setCurrentDirectory old
return res

mpfrVersion = "3.1.2"
mpfrRoot = "deps/mpfr-" ++ mpfrVersion


pathsWithSuffix :: String -> FilePath -> IO [FilePath]
pathsWithSuffix suffix path = do
files <- getDirectoryContents path
return $ map (path </>) (filter (suffix `isSuffixOf`) files)


-- TODO: support Windows nicely
runOrBomb :: FilePath -> [String] -> IO ()
runOrBomb cmd args = do
(c, out, err) <- readProcessWithExitCode cmd args ""
case c of
ExitSuccess -> return ()
ExitFailure e -> do
hPutStrLn stderr $ "Command \"" ++ unwords (cmd:args) ++ "\" failed with exit code: " ++ show e
hPutStrLn stdout $ out
hPutStrLn stderr $ err
exitWith $ ExitFailure e

getConfigDist :: ConfigFlags -> IO FilePath
getConfigDist flags = do
let Flag relDistDir = Flag defaultDistPref `mappend` configDistPref flags
canonicalizePath relDistDir

getBuildDist :: BuildFlags -> IO FilePath
getBuildDist flags = do
let Flag relDistDir = Flag defaultDistPref `mappend` buildDistPref flags
canonicalizePath relDistDir

createDirectory' dir = do
exists <- doesDirectoryExist $ dir
unless exists $ createDirectory dir -- let's hope nobody creates the directory first!

configureMpfr :: FilePath -> IO ()
configureMpfr distDir =
inDirectory mpfrRoot $ do
putStrLn $ "--> Configuring MPFR " ++ mpfrVersion ++ "..."
runOrBomb "sh" ["configure", "--with-gmp=/usr/local", "--prefix=" ++ distDir]

makeMpfr :: FilePath -> IO ()
makeMpfr distDir =
inDirectory mpfrRoot $ do
putStrLn $ "--> Building MPFR " ++ mpfrVersion ++ "..."
runOrBomb "make" ["-j4"]
runOrBomb "make" ["install"]

mpfrHooks :: UserHooks
mpfrHooks = autoconfUserHooks
{ preConf = mpfrPreConf
, postConf = mpfrPostConf
, confHook = mpfrConfHook
, preBuild = mpfrPreBuild
, buildHook = mpfrBuildHook
, postBuild = mpfrPostBuild
, postClean = mpfrPostClean
}
where
mpfrConfHook (pkg, pbi) flags = do
distDir <- getConfigDist flags
lbi <- confHook autoconfUserHooks (pkg, pbi) flags
let lpd = localPkgDescr lbi
lib = fromJust (library lpd)
libbi = libBuildInfo lib
libbi' = libbi { extraLibDirs = (distDir </> "lib") : extraLibDirs libbi }
lib' = lib { libBuildInfo = libbi' }
lpd' = lpd { library = Just lib' }
return lbi { localPkgDescr = lpd' }

-- We need to create the "include" directory at some point, but we're doing it this early to make cabal
-- shut up about it not being present.
mpfrPreConf args flags = do
distDir <- getConfigDist flags
createDirectory' $ distDir </> "include"
createDirectory' $ distDir </> "lib"
createDirectory' $ distDir </> "tmp"
return emptyHookedBuildInfo

mpfrPostConf args flags pkg_descr lbi = do
postConf simpleUserHooks args flags pkg_descr lbi
distDir <- getConfigDist flags
configureMpfr distDir


mpfrPreBuild args flags = do
preBuild simpleUserHooks args flags
distDir <- getBuildDist flags
makeMpfr distDir

let modified = emptyBuildInfo { extraLibs = ["mpfrPIC"]
, extraLibDirs = [distDir </> "libtmp"]
, includeDirs = [distDir </> "include"]
}

return (Just modified, snd emptyHookedBuildInfo)

mpfrBuildHook pkg_descr lbi hooks flags = do
distDir <- getBuildDist flags
(ar, _) <- requireProgram silent arProgram defaultProgramDb
let lbi' = lbi { withPrograms = updateProgram ar (withPrograms lbi) }

putStrLn $ "Determining MPFR constants..."
programExists <- doesFileExist $ distDir </> "mkMpfrDerivedConstants"
unless programExists $ do
Just gcc <- programFindLocation gccProgram normal defaultProgramSearchPath
runOrBomb gcc ["cbits/mkMpfrDerivedConstants.c", "-I/usr/local/Cellar/gmp/5.1.3/include", "-I" ++ distDir </> "include", "-o", distDir </> "mkMpfrDerivedConstants"]
headerExists <- doesFileExist $ distDir </> "include" </> "MpfrDerivedConstants.h"
unless headerExists $ do
header <- readProcess (distDir </> "mkMpfrDerivedConstants") [] ""
writeFile (distDir </> "include" </> "MpfrDerivedConstants.h") header

createDirectory' $ distDir </> "libtmp"
picObjects <- pathsWithSuffix ".o" $ mpfrRoot </> "src" </> ".libs"
createArLibArchive silent lbi' (distDir </> "libtmp" </> "libmpfrPIC.a") picObjects
runOrBomb "ranlib" [distDir </> "libtmp" </> "libmpfrPIC.a"]

buildHook simpleUserHooks pkg_descr lbi' hooks flags

mpfrPostBuild args flags pkg_descr lbi = do
distDir <- getBuildDist flags
(ar, _) <- requireProgram silent arProgram defaultProgramDb
-- (ranlib, _) <- requireProgram silent ranlibProgram defaultProgramDb
let lbi' = lbi { withPrograms = updateProgram ar (withPrograms lbi) }

putStrLn "Mangling static library..."
inDirectory (distDir </> "tmp") $ do
runOrBomb "ar" ["-x", distDir </> "build" </> "libHSrounded-0.1.a"]
runOrBomb "ar" ["-x", distDir </> "lib" </> "libmpfr.a"]

objects <- pathsWithSuffix ".o" $ distDir </> "tmp"
--forM_ objects $ \o -> do
-- runOrBomb "mv" [o, o <.> "tmp"]
-- runOrBomb "objcopy" ["--redefine-syms=rounded.rename", o <.> "tmp", o]

createArLibArchive silent lbi' (distDir </> "build" </> "libHSrounded-0.1.a") objects
runOrBomb "ranlib" [distDir </> "build" </> "libHSrounded-0.1.a"]

profExists <- doesFileExist $ distDir </> "build" </> "libHSrounded-0.1_p.a"
when profExists $ do
putStrLn "Mangling static library (prof)..."
inDirectory (distDir </> "tmp") $ do
runOrBomb "ar" ["-x", distDir </> "build" </> "libHSrounded-0.1_p.a"]
runOrBomb "ar" ["-x", distDir </> "lib" </> "libmpfr.a"]

objects <- pathsWithSuffix ".o" $ distDir </> "tmp"
--forM_ objects $ \o -> do
-- runOrBomb "mv" [o, o <.> "tmp"]
-- runOrBomb "objcopy" ["--redefine-syms=rounded.rename", o <.> "tmp", o]

createArLibArchive silent lbi' (distDir </> "build" </> "libHSrounded-0.1_p.a") objects
runOrBomb "ranlib" [distDir </> "build" </> "libHSrounded-0.1_p.a"]

postBuild simpleUserHooks args flags pkg_descr lbi

mpfrPostClean args flags pkg_descr _ = do
inDirectory mpfrRoot (readProcessWithExitCode "make" ["distclean"] "")
return ()

main :: IO ()
main = defaultMainWithHooks mpfrHooks
main = defaultMain
105 changes: 0 additions & 105 deletions cbits/mkMpfrDerivedConstants.c

This file was deleted.

Loading