Skip to content

Commit

Permalink
Fleshed out the repository
Browse files Browse the repository at this point in the history
  • Loading branch information
ekmett committed Mar 19, 2013
1 parent 55c73a2 commit b1089ec
Show file tree
Hide file tree
Showing 14 changed files with 414 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .ghci
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:set -isrc -idist/build/autogen -optP-include -optPdist/build/autogen/cabal_macros.h -optP-Iincludes
:set -v0
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
dist
docs
wiki
TAGS
tags
wip
contrib
.DS_Store
.*.swp
.*.swo
*.o
*.hi
.svn
*~
*#
Makefile
Makefile.in
aclocal.m4
analytics.buildinfo
autom4te.cache
autoscan.log
config.log
config.guess
config.status
config.sub
config.h
config.h.in
configure
configure.scan
depcomp
install-sh
missing
www
stamp-h1
config.h.in
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
language: haskell
before_install:
# Uncomment whenever hackage is down.
# - mkdir -p ~/.cabal && cp travis/config ~/.cabal/config && cabal update
- cabal update

# Try installing some of the build-deps with apt-get for speed.
- travis/cabal-apt-install $mode

install:
- cabal configure -flib-Werror $mode
- cabal build

script:
- $script && hlint src --cpp-define HLINT

notifications:
irc:
channels:
- "irc.freenode.org#haskell-lens"
skip_join: true
template:
- "\x0313compensated\x03/\x0306%{branch}\x03 \x0314%{commit}\x03 %{build_url} %{message}"

env:
- mode="--enable-tests" script="cabal test --show-details=always"
31 changes: 31 additions & 0 deletions .vim.custom
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
" Add the following to your .vimrc to automatically load this on startup

" if filereadable(".vim.custom")
" so .vim.custom
" endif

function StripTrailingWhitespace()
let myline=line(".")
let mycolumn = col(".")
silent %s/ *$//
call cursor(myline, mycolumn)
endfunction

" enable syntax highlighting
syntax on

" search for the tags file anywhere between here and /
set tags=TAGS;/

" highlight tabs and trailing spaces
set listchars=tab:‗‗,trail:‗
set list

" f2 runs hasktags
map <F2> :exec ":!hasktags -x -c --ignore src"<CR><CR>

" strip trailing whitespace before saving
" au BufWritePre *.hs,*.markdown silent! cal StripTrailingWhitespace()

" rebuild hasktags after saving
au BufWritePost *.hs silent! :exec ":!hasktags -x -c --ignore src"
3 changes: 3 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0.1
---
* Split from [analytics](https://github.com/analytics/analytics)
1 change: 1 addition & 0 deletions HLint.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "hint" HLint.Default
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright 2013 Edward Kmett

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the author nor the names of his contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
23 changes: 23 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
compensated
===========

[![Build Status](https://secure.travis-ci.org/ekmett/compensated.png)](http://travis-ci.org/ekmett/compensated)

This package provides a form of compensated arithmetic that lets you perform many operations on chains of doubles at higher precision.

In particular addition, multiplication, etc. on a `Compensated Double` is done with twice as many bits of `significand` as on a raw `Double`.

This construction is designed so that it can be iterated.

This was forked from the [analytics](http://github.com/analytics/analytics.git) repository after repeated requests.

Work still needs to be done to properly support most `Floating` operations, but everything below that level of the numeric hierarchy should work.

Contact Information
-------------------

Contributions and bug reports are welcome!

Please feel free to contact me through github or on the #haskell IRC channel on irc.freenode.net.

-Edward Kmett
55 changes: 55 additions & 0 deletions Setup.lhs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/runhaskell
\begin{code}
{-# OPTIONS_GHC -Wall #-}
module Main (main) where

import Data.List ( nub )
import Data.Version ( showVersion )
import Distribution.Package ( PackageName(PackageName), Package, PackageId, InstalledPackageId, packageVersion, packageName )
import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )
import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose, copyFiles )
import Distribution.Simple.BuildPaths ( autogenModulesDir )
import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), Flag(..), fromFlag, HaddockFlags(haddockDistPref))
import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )
import Distribution.Text ( display )
import Distribution.Verbosity ( Verbosity, normal )
import System.FilePath ( (</>) )

main :: IO ()
main = defaultMainWithHooks simpleUserHooks
{ buildHook = \pkg lbi hooks flags -> do
generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
buildHook simpleUserHooks pkg lbi hooks flags
, postHaddock = \args flags pkg lbi -> do
copyFiles normal (haddockOutputDir flags pkg) [("images","Hierarchy.png")]
postHaddock simpleUserHooks args flags pkg lbi
}

haddockOutputDir :: Package p => HaddockFlags -> p -> FilePath
haddockOutputDir flags pkg = destDir where
baseDir = case haddockDistPref flags of
NoFlag -> "."
Flag x -> x
destDir = baseDir </> "doc" </> "html" </> display (packageName pkg)

generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()
generateBuildModule verbosity pkg lbi = do
let dir = autogenModulesDir lbi
createDirectoryIfMissingVerbose verbosity True dir
withLibLBI pkg lbi $ \_ libcfg -> do
withTestLBI pkg lbi $ \suite suitecfg -> do
rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines
[ "module Build_" ++ testName suite ++ " where"
, "deps :: [String]"
, "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))
]
where
formatdeps = map (formatone . snd)
formatone p = case packageName p of
PackageName n -> n ++ "-" ++ showVersion (packageVersion p)

testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys

\end{code}
87 changes: 87 additions & 0 deletions compensated.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: compensated
category: Numeric
version: 0.1
license: BSD3
cabal-version: >= 1.8
license-file: LICENSE
author: Edward A. Kmett
maintainer: Edward A. Kmett <ekmett@gmail.com>
stability: provisional
homepage: http://github.com/analytics/compensated/
bug-reports: http://github.com/analytics/compensated/issues
copyright: Copyright (C) 2013 Edward A. Kmett
build-type: Custom
tested-with: GHC == 7.4.1, GHC == 7.6.1
synopsis: Compensated floating-point arithmetic
description: This package provides compensated floating point arithmetic.

extra-source-files:
.travis.yml
.ghci
.gitignore
.vim.custom
travis/cabal-apt-install
travis/config
AUTHORS.markdown
README.markdown
CHANGELOG.markdown

source-repository head
type: git
location: git://github.com/analytics/compensated.git

-- You can disable the doctests test suite with -f-test-doctests
flag test-doctests
default: True
manual: True

flag lib-Werror
default: False
manual: True

library
build-depends:
base >= 4.3 && < 5,
bifunctors >= 3.2 && < 4,
binary >= 0.5 && < 0.6,
comonad >= 3 && < 4,
deepseq >= 1.3 && < 1.5,
distributive >= 0.3 && < 1,
generic-deriving == 1.4.*,
hashable >= 1.1.2.3 && < 1.3,
lens >= 3.8 && < 3.9,
log-domain >= 0.2 && < 1,
semigroupoids >= 3.0.2 && < 4,
semigroups >= 0.8.4 && < 1,
safecopy >= 0.8.1 && < 0.9,
vector >= 0.9 && < 0.11

exposed-modules:
Numeric.Compensated

if flag(lib-Werror)
ghc-options: -Werror

ghc-options: -Wall -fwarn-tabs -O2
hs-source-dirs: src

test-suite doctests
type: exitcode-stdio-1.0
main-is: doctests.hs
ghc-options: -Wall -threaded
hs-source-dirs: tests

if !flag(test-doctests)
buildable: False
else
build-depends:
base,
directory >= 1.0,
doctest >= 0.9.1,
filepath,
generic-deriving,
semigroups >= 0.9,
simple-reflect >= 0.3.1

if impl(ghc<7.6.1)
ghc-options: -Werror
7 changes: 4 additions & 3 deletions src/Numeric/Compensated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE PatternGuards #-}
--------------------------------------------------------------------
-- |
-- Copyright : (c) Edward Kmett 2013
Expand All @@ -31,7 +32,7 @@
-- * Donald Knuth's \"The Art of Computer Programming, Volume 2: Seminumerical Algorithms\"
-- * <http://en.wikipedia.org/wiki/Kahan_summation_algorithm>
--------------------------------------------------------------------
module Data.Analytics.Numeric.Compensated
module Numeric.Compensated
( Compensable(..)
, _Compensated
, Overcompensated
Expand Down Expand Up @@ -343,12 +344,12 @@ kahan = Foldable.foldr (+^) mempty
{-# INLINE kahan #-}

-- (<|) = (+^)
instance (Bifunctor p, Profunctor p, Functor f, Compensable a, a ~ b) => Cons p f (Compensated a) (Compensated b) a b where
instance (Reviewable p, Functor f, Compensable a, a ~ b) => Cons p f (Compensated a) (Compensated b) a b where
_Cons = unto $ \(a, e) -> with e $ \b c -> let y = a - c; t = b + y in compensated t ((t - b) - y)
{-# INLINE _Cons #-}

-- (|>) = (+^)
instance (Bifunctor p, Profunctor p, Functor f, Compensable a, a ~ b) => Snoc p f (Compensated a) (Compensated b) a b where
instance (Reviewable p, Functor f, Compensable a, a ~ b) => Snoc p f (Compensated a) (Compensated b) a b where
_Snoc = unto $ \(e, a) -> with e $ \b c -> let y = a - c; t = b + y in compensated t ((t - b) - y)
{-# INLINE _Snoc #-}

Expand Down
Loading

0 comments on commit b1089ec

Please sign in to comment.