From 7e36f24d11a0366956d7822d0c5fc87148aa4a60 Mon Sep 17 00:00:00 2001 From: Julia Longtin Date: Wed, 20 Dec 2023 15:36:33 +0000 Subject: [PATCH 1/5] change maintainer, and clarify comments. --- src/Data/Bits/Floating.hs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Data/Bits/Floating.hs b/src/Data/Bits/Floating.hs index 468cd36..c8b5de3 100644 --- a/src/Data/Bits/Floating.hs +++ b/src/Data/Bits/Floating.hs @@ -1,14 +1,15 @@ {-# LANGUAGE FunctionalDependencies #-} ----------------------------------------------------------------------------- -- | --- Copyright : (C) 2015 Anselm Jonas Scholl +-- Copyright : (C) 2015 Anselm Jonas Scholl, (C) 2023 Julia Longtin -- License : BSD3 --- Maintainer : Anselm Jonas Scholl +-- Maintainer : Julia Longtin -- Stability : experimental -- Portability : GHC-specific -- --- Conversions between floating point values and integral values preserving --- the bit-patterns. +-- Functions for performing conversions between floating point values and +-- Integral values, for retrieving the Unit of Least Precision of a floating +-- point value, and for incrementing / decrementing a value by one ULP.. ---------------------------------------------------------------------------- module Data.Bits.Floating ( @@ -57,14 +58,16 @@ class (Floating f, Integral w) => FloatingBits f w | f -> w where -- @'coerceToWord' ('coerceToFloat' w) /= w@. coerceToFloat :: w -> f -- | Return the next floating point value in the direction of +INF. - -- If the argument is NaN, NaN is returned. If the argument is +INF, - -- +INF is returned. If the argument is 0.0, the minimum value greater than - -- 0.0 is returned. + -- If the argument is NaN, NaN is returned. + -- If the argument is +INF, +INF is returned. + -- If the argument is 0.0, the minimum value greater than 0.0 is returned. + -- If the argument is -INF, -INF is returned. nextUp :: f -> f -- | Return the next floating point value in the direction of -INF. - -- If the argument is NaN, NaN is returned. If the argument is -INF, - -- +INF is returned. If the argument is 0.0, the maximum value smaller than - -- 0.0 is returned. + -- If the argument is NaN, NaN is returned. + -- If the argument is +INF, +INF is returned. + -- If the argument is 0.0, the maximum value smaller than 0.0 is returned. + -- If the argument is -INF, -INF is returned. nextDown :: f -> f -- | Return the size of an ulp of the argument. If the argument is NaN, NaN -- is returned. If the argument is +INF or -INF, +INF is returned. If From f9a113b30f3464aa3df995c76b8bafb15f5adf34 Mon Sep 17 00:00:00 2001 From: Julia Longtin Date: Wed, 20 Dec 2023 23:03:40 +0000 Subject: [PATCH 2/5] add another license header, and qualify imports. --- src/Data/Bits/Floating.hs | 9 +++++---- src/Data/Bits/Floating/Prim.hs | 4 ++-- test/Test.hs | 28 +++++++++++++++++++++------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Data/Bits/Floating.hs b/src/Data/Bits/Floating.hs index c8b5de3..cce8c13 100644 --- a/src/Data/Bits/Floating.hs +++ b/src/Data/Bits/Floating.hs @@ -69,11 +69,12 @@ class (Floating f, Integral w) => FloatingBits f w | f -> w where -- If the argument is 0.0, the maximum value smaller than 0.0 is returned. -- If the argument is -INF, -INF is returned. nextDown :: f -> f - -- | Return the size of an ulp of the argument. If the argument is NaN, NaN - -- is returned. If the argument is +INF or -INF, +INF is returned. If - -- the argument is 0.0, the minimum value greater than 0.0 is returned. + -- | Return the size of the Unit of Least Precision of the argument. + -- If the argument is NaN, NaN is returned. + -- If the argument is +INF or -INF, +INF is returned. + -- If the argument is 0.0, the minimum value greater than 0.0 is returned. -- - -- If @x@ is not NaN, @'ulp' x == 'ulp' (-x)@ holds. + -- If @x@ is not NaN or one of the infinities, @'ulp' x == 'ulp' (-x)@ holds. ulp :: f -> f class ShowFloat f where diff --git a/src/Data/Bits/Floating/Prim.hs b/src/Data/Bits/Floating/Prim.hs index c8fcd71..cb0a4ff 100644 --- a/src/Data/Bits/Floating/Prim.hs +++ b/src/Data/Bits/Floating/Prim.hs @@ -1,8 +1,8 @@ ----------------------------------------------------------------------------- -- | --- Copyright : (C) 2015 Anselm Jonas Scholl +-- Copyright : (C) 2015 Anselm Jonas Scholl, (C) 2023 Julia Longtin -- License : BSD3 --- Maintainer : Anselm Jonas Scholl +-- Maintainer : Julia Longtin -- Stability : experimental -- Portability : GHC-specific -- diff --git a/test/Test.hs b/test/Test.hs index 3c5d3da..1917253 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -1,16 +1,30 @@ +----------------------------------------------------------------------------- +-- | +-- Copyright : (C) 2015 Anselm Jonas Scholl, (C) 2023 Julia Longtin +-- License : BSD3 +-- Maintainer : Julia Longtin +-- Stability : experimental +-- Portability : GHC-specific +-- + {-# LANGUAGE BangPatterns #-} + {-# LANGUAGE ScopedTypeVariables #-} + module Main where -import TestUtils +import Prelude(Bool(False), Double, Float, Integral, IO, MonadFail, RealFloat, Show, String, (.), (<), ($), (+), (-), (&&), (++), (<=), (>=), (/=), (==), (||), (<$>), either, fail, fromIntegral, fst, isInfinite, isNaN, isNegativeZero, mapM_, maxBound, minBound, not, otherwise, putStrLn, realToFrac, rem, return, quot, show, shows, snd) + +import TestUtils (refDoubleDown, refDoubleToWord, refDoubleUp, refDoubleUlp, refFloatDown, refFloatToWord, refFloatUlp, refFloatUp, refWordToDouble, refWordToFloat, showW, testD, testF) + +import Data.Word (Word32, Word64) -import Data.Word -import Data.Bits -import Data.Bits.Floating +import Data.Bits ((.&.), complement) +import Data.Bits.Floating (FloatingBits, ShowFloat, coerceToFloat, coerceToWord, nextDown, nextUp, showFloat, ulp) -import Control.Concurrent -import Control.Exception -import Control.Monad +import Control.Concurrent (MVar, forkIO, getNumCapabilities, newEmptyMVar, putMVar, takeMVar) +import Control.Exception (SomeException, throwIO, try) +import Control.Monad (forM_, join, replicateM_, unless, void, when) main :: IO () main = do From 2aed344efea0cfe47e1ecde25d365cd5b671be21 Mon Sep 17 00:00:00 2001 From: Julia Longtin Date: Fri, 22 Dec 2023 22:20:09 +0000 Subject: [PATCH 3/5] add more qualification and license headers --- test/Bench.hs | 20 ++++++++++++++++---- test/TestUtils.hs | 16 ++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/test/Bench.hs b/test/Bench.hs index 0ae3856..14bd2f0 100644 --- a/test/Bench.hs +++ b/test/Bench.hs @@ -1,11 +1,23 @@ +----------------------------------------------------------------------------- +-- | +-- Copyright : (C) 2015 Anselm Jonas Scholl, (C) 2023 Julia Longtin +-- License : BSD3 +-- Maintainer : Julia Longtin +-- Stability : experimental +-- Portability : GHC-specific +-- + module Main where -import TestUtils +import Prelude (Double, Float, IO, ($), (++), concatMap, map, shows, unzip) + +import TestUtils (refDoubleDown, refDoubleToWord, refDoubleUp, refDoubleUlp, refFloatDown, refFloatToWord, refFloatUp, refFloatUlp, refWordToDouble, refWordToFloat, showW, testD, testF) + +import Data.Word (Word32, Word64) -import Data.Word -import Data.Bits.Floating +import Data.Bits.Floating (coerceToFloat, coerceToWord, nextDown, nextUp, ulp) -import Criterion.Main +import Criterion.Main (Benchmark, bench, bgroup, defaultMain, nf) mkSingleBenchmarks :: ((Float, Word32) -> [Benchmark]) -> ((Double, Word64) -> [Benchmark]) -> [Benchmark] mkSingleBenchmarks mkFTest mkDTest = concatMap mkFTest testF ++ concatMap mkDTest testD diff --git a/test/TestUtils.hs b/test/TestUtils.hs index f265e43..88dfb35 100644 --- a/test/TestUtils.hs +++ b/test/TestUtils.hs @@ -1,9 +1,21 @@ +----------------------------------------------------------------------------- +-- | +-- Copyright : (C) 2015 Anselm Jonas Scholl, (C) 2023 Julia Longtin +-- License : BSD3 +-- Maintainer : Julia Longtin +-- Stability : experimental +-- Portability : GHC-specific +-- + {-# LANGUAGE ForeignFunctionInterface #-} + module TestUtils where -import Data.Word +import Prelude (Double, Float, Integral, Show, String, (/), pi, sqrt) + +import Data.Word (Word32, Word64) -import Numeric +import Numeric (showHex) -- we do not test NaNs here because their binary representation can be changed -- without changing their value and some processors have been observed to do that. From b347216ecb21c004a5f448d60203f30e6d2bf739 Mon Sep 17 00:00:00 2001 From: Julia Longtin Date: Sat, 23 Dec 2023 14:14:12 +0000 Subject: [PATCH 4/5] let hlint run without erroring out. --- src/Data/Bits/Floating/Prim.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Data/Bits/Floating/Prim.hs b/src/Data/Bits/Floating/Prim.hs index cb0a4ff..f4e7dd4 100644 --- a/src/Data/Bits/Floating/Prim.hs +++ b/src/Data/Bits/Floating/Prim.hs @@ -17,6 +17,7 @@ {-# LANGUAGE UnliftedFFITypes #-} {-# LANGUAGE CPP #-} +-- Note: HLint fails to find this, and will always warn. #include "MachDeps.h" module Data.Bits.Floating.Prim ( @@ -31,6 +32,7 @@ import Prelude () import GHC.Exts (Double#, Double(D#), Float#, Float(F#)) import GHC.Word (Word32(W32#), Word64(W64#)) +#if defined(WORD_SIZE_IN_BITS) #if WORD_SIZE_IN_BITS == 64 && MIN_VERSION_base(4,17,0) -- The name of Word# changed to Word64# in base 4.17.0 (GHC 9.4.1) import GHC.Exts (Word64#, Word32#) @@ -52,6 +54,7 @@ import GHC.Exts (Word32#) #else #error non-X86_64 architectures not supported #endif +#endif foreign import prim "double2WordBwzh" double2WordBitwise# :: Double# -> WORD64# From e1d03c02ab54a64c3f7db9745171637018fe42d7 Mon Sep 17 00:00:00 2001 From: Julia Longtin Date: Sat, 23 Dec 2023 17:57:18 +0000 Subject: [PATCH 5/5] update contact information. --- floating-bits.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/floating-bits.cabal b/floating-bits.cabal index 870b3a7..13efe96 100644 --- a/floating-bits.cabal +++ b/floating-bits.cabal @@ -5,7 +5,7 @@ description: A small library to cast floating point values to integral v license: BSD3 license-file: LICENSE author: Anselm Jonas Scholl -maintainer: julia.longtin@gmail.com +maintainer: Julia Longtin copyright: (c) 2015 Anselm Jonas Scholl, (c) 2023 Julia Longtin category: Data build-type: Simple