packages feed

numeric-extras (empty) → 0.0.1

raw patch · 4 files changed

+126/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,31 @@+Copyright (c) 2010, 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:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * 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.++    * Neither the name of Edward Kmett nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"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 COPYRIGHT+OWNER 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.
+ Numeric/Extras.hs view
@@ -0,0 +1,76 @@+{-# LANGUAGE ForeignFunctionInterface, FlexibleContexts, TypeFamilies #-}+module Numeric.Extras+    ( RealExtras(..)+    ) where++import Foreign+import Foreign.C.Types++class (Storable (C a), RealFloat (C a), RealFloat a) => RealExtras a where+    type C a :: *+    fmod :: a -> a -> a+    expm1 :: a -> a+    log1p :: a -> a+    hypot :: a -> a -> a+    cbrt  :: a -> a+    erf   :: a -> a++instance RealExtras Double where+    type C Double = CDouble+    fmod = lift2D c_fmod+    expm1 = lift1D c_expm1+    log1p = lift1D c_log1p+    hypot = lift2D c_hypot+    cbrt = lift1D c_cbrt+    erf = lift1D c_erf++lift1D :: (CDouble -> CDouble) -> Double -> Double+lift1D f a = realToFrac (f (realToFrac a))+{-# INLINE lift1D #-}++lift2D :: (CDouble -> CDouble -> CDouble) -> Double -> Double -> Double+lift2D f a b = realToFrac (f (realToFrac a) (realToFrac b))+{-# INLINE lift2D #-}++instance RealExtras Float where+    type C Float = CFloat+    fmod = lift2F c_fmodf+    expm1 = lift1F c_expm1f+    log1p = lift1F c_log1pf+    hypot = lift2F c_hypotf+    cbrt  = lift1F c_cbrtf+    erf   = lift1F c_erff++lift1F :: (CFloat -> CFloat) -> Float -> Float+lift1F f a = realToFrac (f (realToFrac a))+{-# INLINE lift1F #-}++lift2F :: (CFloat -> CFloat -> CFloat) -> Float -> Float -> Float+lift2F f a b = realToFrac (f (realToFrac a) (realToFrac b))+{-# INLINE lift2F #-}++foreign import ccall unsafe "math.h fmod" +    c_fmod :: CDouble -> CDouble -> CDouble+foreign import ccall unsafe "math.h expm1" +    c_expm1 :: CDouble -> CDouble+foreign import ccall unsafe "math.h log1p" +    c_log1p :: CDouble -> CDouble+foreign import ccall unsafe "math.h hypot" +    c_hypot :: CDouble -> CDouble -> CDouble+foreign import ccall unsafe "math.h cbrt" +    c_cbrt :: CDouble -> CDouble+foreign import ccall unsafe "math.h erf"+    c_erf :: CDouble -> CDouble++foreign import ccall unsafe "math.h fmodf" +    c_fmodf :: CFloat -> CFloat -> CFloat+foreign import ccall unsafe "math.h expm1f" +    c_expm1f :: CFloat -> CFloat+foreign import ccall unsafe "math.h log1pf" +    c_log1pf :: CFloat -> CFloat+foreign import ccall unsafe "math.h hypotf" +    c_hypotf :: CFloat -> CFloat -> CFloat+foreign import ccall unsafe "math.h cbrtf" +    c_cbrtf :: CFloat -> CFloat+foreign import ccall unsafe "math.h erff"+    c_erff :: CFloat -> CFloat
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMainWithHooks simpleUserHooks
+ numeric-extras.cabal view
@@ -0,0 +1,16 @@+Name:              numeric-extras+Version:           0.0.1+Synopsis:          Useful tools from the C standard library+Homepage:          http://patch-tag.com/r/ekmett/numeric-extras+License:           BSD3+License-file:      LICENSE+Author:            Edward Kmett+Maintainer:        ekmett@gmail.com+Category:          Math+Build-type:        Simple+Cabal-version:     >=1.6++Library+  Exposed-modules: Numeric.Extras+  Build-depends:   base >= 4 && < 5+  GHC-Options:     -Wall -O2