fp-ieee 0.1.0.3 → 0.1.0.4
raw patch · 8 files changed
+51/−6 lines, 8 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−0
- LICENSE +1/−1
- doctests.hs +3/−0
- fp-ieee.cabal +2/−2
- src/Numeric/Floating/IEEE.hs +4/−3
- src/Numeric/Floating/IEEE/Internal/Augmented.hs +35/−0
- src/Numeric/Floating/IEEE/Internal/Base.hs +1/−0
- src/Numeric/Floating/IEEE/Internal/NextFloat.hs +1/−0
ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for fp-ieee +## Version 0.1.0.4 (2024-02-18)++* Documentation chanegs.+ ## Version 0.1.0.3 (2023-11-18) * Allow ghc-bignum 1.3.
LICENSE view
@@ -1,4 +1,4 @@-Copyright ARATA Mizuki (c) 2020+Copyright ARATA Mizuki (c) 2020-2024 All rights reserved.
doctests.hs view
@@ -3,6 +3,7 @@ main :: IO () main = doctest [ "-isrc" , "-fobject-code" -- for GHC 8.6+ , "src/Numeric/Floating/IEEE/Internal/Augmented.hs" , "src/Numeric/Floating/IEEE/Internal/Base.hs" , "src/Numeric/Floating/IEEE/Internal/Classify.hs" , "src/Numeric/Floating/IEEE/Internal/FMA.hs"@@ -10,5 +11,7 @@ , "src/Numeric/Floating/IEEE/Internal/IntegerInternals.hs" , "src/Numeric/Floating/IEEE/Internal/MinMax.hs" , "src/Numeric/Floating/IEEE/Internal/NextFloat.hs"+ , "src/Numeric/Floating/IEEE/Internal/Rounding/Common.hs"+ , "src/Numeric/Floating/IEEE/Internal/Rounding/Rational.hs" , "src/Numeric/Floating/IEEE/Internal/RoundToIntegral.hs" ]
fp-ieee.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2 name: fp-ieee-version: 0.1.0.3+version: 0.1.0.4 synopsis: IEEE 754-2019 compliant operations description: Please see the README on GitHub at <https://github.com/minoki/haskell-floating-point/tree/master/fp-ieee#readme> category: Numeric, Math@@ -9,7 +9,7 @@ bug-reports: https://github.com/minoki/haskell-floating-point/issues author: ARATA Mizuki maintainer: minorinoki@gmail.com-copyright: 2020-2023 ARATA Mizuki+copyright: 2020-2024 ARATA Mizuki license: BSD-3-Clause license-file: LICENSE build-type: Simple
src/Numeric/Floating/IEEE.hs view
@@ -118,7 +118,7 @@ -- -- | -- For IEEE-compliant floating-point types, 'negate' from "Prelude" should comply with IEEE semantics.- -- 'abs' should also comply with IEEE semantics, but unfortunately it does not handle the sign bit of NaN on via-C backend and SPARC NCG backend.+ -- On GHC 9.6 or later, 'abs' should also comply with IEEE semantics (GHC <= 9.4 did not handle the sign bit of NaN on via-C backend and SPARC NCG backend). , negate , abs -- |@@ -210,8 +210,9 @@ -- -- * '(+)', '(-)', and '(*)' should be correctly-rounding. -- * 'negate' should comply with IEEE semantics.--- * 'abs' should comply with IEEE semantics, but unfortunately it does not handle the sign bit of NaN for 'Float' and 'Double' on via-C backend and SPARC NCG backend.--- * 'fromInteger' should be correctly-rounding, but unfortunately not for 'Float' and 'Double' on GHC <= 9.0 (see GHC's [#17231](https://gitlab.haskell.org/ghc/ghc/-/issues/17231)).+-- * 'abs' should comply with IEEE semantics (GHC <= 9.4 did not handle the sign bit of NaN for 'Float' and 'Double' on via-C backend and SPARC NCG backend. See GHC's [#21043](https://gitlab.haskell.org/ghc/ghc/-/issues/21043)).+-- * 'fromInteger' should be correctly-rounding, but some third-party floating-point types may fail to do so+-- (also, GHC <= 9.0 failed to do so for 'Float' and 'Double'. See GHC's [#17231](https://gitlab.haskell.org/ghc/ghc/-/issues/17231)). -- This module provides an always-correctly-rounding alternative: 'fromIntegerTiesToEven'. -- -- == 'Fractional'
src/Numeric/Floating/IEEE/Internal/Augmented.hs view
@@ -12,8 +12,33 @@ default () +-- $setup+-- >>> :set -XDeriveFunctor+-- >>> import Numeric.Floating.IEEE.Internal.Augmented+-- >>> import Numeric.Floating.IEEE.Internal.Rounding.Common+-- >>> import Numeric.Floating.IEEE.Internal.Rounding.Rational+-- >>> :{+-- newtype RoundTiesTowardZero a = RoundTiesTowardZero { roundTiesTowardZero :: a }+-- deriving (Functor)+-- instance RoundingStrategy RoundTiesTowardZero where+-- exact = RoundTiesTowardZero+-- inexact o _neg _parity zero away = RoundTiesTowardZero $ case o of+-- LT -> zero+-- EQ -> zero+-- GT -> away+-- doRound _exact o _neg _parity zero away = RoundTiesTowardZero $ case o of+-- LT -> zero+-- EQ -> zero+-- GT -> away+-- :}+ -- | -- IEEE 754 @augmentedAddition@ operation.+--+-- The first return value is the approximation of the sum, and the second return value is the error.+--+-- prop> fst (augmentedAddition x y) == roundTiesTowardZero (fromRationalR (toRational x + toRational y)) `const` (x :: Double)+-- prop> let (u, v) = augmentedAddition x y in toRational u + toRational v == toRational x + toRational y `const` (x :: Double) augmentedAddition :: RealFloat a => a -> a -> (a, a) augmentedAddition !x !y | isNaN x || isInfinite x || isNaN y || isInfinite y = let !result = x + y in (result, result)@@ -50,11 +75,21 @@ -- | -- IEEE 754 @augmentedSubtraction@ operation.+--+-- The first return value is the approximation of the difference, and the second return value is the error.+--+-- prop> fst (augmentedSubtraction x y) == roundTiesTowardZero (fromRationalR (toRational x - toRational y)) `const` (x :: Double)+-- prop> let (u, v) = augmentedSubtraction x y in toRational u + toRational v == toRational x - toRational y `const` (x :: Double) augmentedSubtraction :: RealFloat a => a -> a -> (a, a) augmentedSubtraction x y = augmentedAddition x (negate y) -- | -- IEEE 754 @augmentedMultiplication@ operation.+--+-- The first return value is the approximation of the product, and the second return value is the error.+--+-- prop> fst (augmentedMultiplication x y) == roundTiesTowardZero (fromRationalR (toRational x * toRational y)) `const` (x :: Double)+-- prop> let (u, v) = augmentedMultiplication x y in toRational u + toRational v == toRational x * toRational y `const` (x :: Double) augmentedMultiplication :: RealFloat a => a -> a -> (a, a) augmentedMultiplication !x !y | isNaN x || isInfinite x || isNaN y || isInfinite y || x * y == 0 = let !result = x * y in (result, result)
src/Numeric/Floating/IEEE/Internal/Base.hs view
@@ -17,6 +17,7 @@ -- $setup -- >>> :set -XHexFloatLiterals -XNumericUnderscores -- >>> import Numeric.Floating.IEEE.Internal.NextFloat (nextDown)+-- >>> import Numeric.Floating.IEEE.Internal.Base isFloatBinary32 :: Bool isFloatBinary32 = isIEEE x
src/Numeric/Floating/IEEE/Internal/NextFloat.hs view
@@ -12,6 +12,7 @@ -- $setup -- >>> :set -XHexFloatLiterals -XNumericUnderscores+-- >>> import Numeric.Floating.IEEE.Internal.Base -- >>> import Numeric.Floating.IEEE.Internal.NextFloat -- |