{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- |
-- Module      : Graphics.Color.Algebra.Elevator
-- Copyright   : (c) Alexey Kuleshevich 2018-2020
-- License     : BSD3
-- Maintainer  : Alexey Kuleshevich <lehins@yandex.ru>
-- Stability   : experimental
-- Portability : non-portable
--
module Graphics.Color.Algebra.Elevator
  ( Elevator(..)
  , module Data.Word
  , clamp01
  ) where

import Data.Complex
import Data.Int
import Data.Typeable
import Data.Vector.Storable (Storable)
import Data.Vector.Unboxed (Unbox)
import Data.Word
import GHC.Float
import Text.Printf

infixl 7 //

defFieldFormat :: FieldFormat
defFieldFormat :: FieldFormat
defFieldFormat = Maybe Int
-> Maybe Int
-> Maybe FormatAdjustment
-> Maybe FormatSign
-> Bool
-> String
-> Char
-> FieldFormat
FieldFormat Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe FormatAdjustment
forall a. Maybe a
Nothing Maybe FormatSign
forall a. Maybe a
Nothing Bool
False String
"" Char
'v'

-- | A class with a set of functions that allow for changing precision by shrinking and
-- streatching the values.
class (Show e, Eq e, Num e, Typeable e, Unbox e, Storable e) => Elevator e where
  maxValue :: e

  minValue :: e

  fieldFormat :: e -> FieldFormat
  fieldFormat e
_ = FieldFormat
defFieldFormat

  -- | This is a pretty printer for the value.
  toShowS :: e -> ShowS
  default toShowS :: PrintfArg e => e -> ShowS
  toShowS e
e = e -> FieldFormatter
forall a. PrintfArg a => a -> FieldFormatter
formatArg e
e (e -> FieldFormat
forall e. Elevator e => e -> FieldFormat
fieldFormat e
e)

  -- | Values are scaled to @[0, 255]@ range.
  toWord8 :: e -> Word8

  -- | Values are scaled to @[0, 65535]@ range.
  toWord16 :: e -> Word16

  -- | Values are scaled to @[0, 4294967295]@ range.
  toWord32 :: e -> Word32

  -- | Values are scaled to @[0, 18446744073709551615]@ range.
  toWord64 :: e -> Word64

  -- | Values are scaled to @[0.0, 1.0]@ range.
  toRealFloat :: (Elevator a, RealFloat a) => e -> a

  -- | Values are scaled from @[0.0, 1.0]@ range.
  fromRealFloat :: (Elevator a, RealFloat a) => a -> e

  -- | Values are scaled to @[0.0, 1.0]@ range.
  toFloat :: e -> Float
  toFloat = e -> Float
forall e a. (Elevator e, Elevator a, RealFloat a) => e -> a
toRealFloat

  -- | Values are scaled to @[0.0, 1.0]@ range.
  toDouble :: e -> Double
  toDouble = e -> Double
forall e a. (Elevator e, Elevator a, RealFloat a) => e -> a
toRealFloat

  -- | Values are scaled from @[0.0, 1.0]@ range.
  fromDouble :: Double -> e
  fromDouble = Double -> e
forall e a. (Elevator e, Elevator a, RealFloat a) => a -> e
fromRealFloat

  -- | Division that works for integral types as well as floating points. May throw an exception.
  (//) :: e -> e -> e


-- | Lower the precision
dropDown :: forall a b. (Integral a, Bounded a, Integral b, Bounded b) => a -> b
dropDown :: a -> b
dropDown !a
e = a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral (a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ a -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
e a -> a -> a
forall a. Integral a => a -> a -> a
`div` ((a
forall a. Bounded a => a
maxBound :: a) a -> a -> a
forall a. Integral a => a -> a -> a
`div`
                                                   b -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (b
forall a. Bounded a => a
maxBound :: b))
{-# INLINE dropDown #-}

-- | Increase the precision
raiseUp :: forall a b. (Integral a, Bounded a, Integral b, Bounded b) => a -> b
raiseUp :: a -> b
raiseUp !a
e = a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
e b -> b -> b
forall a. Num a => a -> a -> a
* ((b
forall a. Bounded a => a
maxBound :: b) b -> b -> b
forall a. Integral a => a -> a -> a
`div` a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral (a
forall a. Bounded a => a
maxBound :: a))
{-# INLINE raiseUp #-}

-- | Convert to fractional with value less than or equal to 1.
squashTo1 :: forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1 :: a -> b
squashTo1 !a
e = a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
e b -> b -> b
forall a. Fractional a => a -> a -> a
/ a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral (a
forall a. Bounded a => a
maxBound :: a)
{-# INLINE squashTo1 #-}

-- | Convert to integral streaching it's value up to a maximum value.
stretch :: forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch :: a -> b
stretch !a
e = a -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (b -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (b
forall a. Bounded a => a
maxBound :: b) a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. RealFloat a => a -> a
clamp01 a
e)
{-# INLINE stretch #-}

-- | Clamp a value to @[0, 1]@ range.
clamp01 :: RealFloat a => a -> a
clamp01 :: a -> a
clamp01 !a
x = a -> a -> a
forall a. Ord a => a -> a -> a
min (a -> a -> a
forall a. Ord a => a -> a -> a
max a
0 a
x) a
1
{-# INLINE clamp01 #-}


float2Word32 :: Float -> Word32
float2Word32 :: Float -> Word32
float2Word32 Float
d'
  | Float
d' Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
<= Float
0 = Word32
0
  | Float
d Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
> Float
4.294967e9 = Word32
forall a. Bounded a => a
maxBound
  | Bool
otherwise = Float -> Word32
forall a b. (RealFrac a, Integral b) => a -> b
round Float
d
  where
    d :: Float
d = Float
maxWord32 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
d'
{-# INLINE float2Word32 #-}

-- | Same as:
-- >>> fromIntegral (maxBound :: Word32) :: Float
-- 4.2949673e9
--
maxWord32 :: Float
maxWord32 :: Float
maxWord32 = Float# -> Float
F# Float#
4.2949673e9#
{-# INLINE maxWord32 #-}

double2Word64 :: Double -> Word64
double2Word64 :: Double -> Word64
double2Word64 Double
d'
  | Double
d' Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
<= Double
0 = Word64
0
  | Double
d Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
1.844674407370955e19 = Word64
forall a. Bounded a => a
maxBound
  | Bool
otherwise = Double -> Word64
forall a b. (RealFrac a, Integral b) => a -> b
round Double
d
  where
    d :: Double
d = Double
maxWord64 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
d'
{-# INLINE double2Word64 #-}

-- | Differs from `fromIntegral` due to: [GHC #17782](https://gitlab.haskell.org/ghc/ghc/issues/17782)
--
-- >>> fromIntegral (maxBound :: Word64) :: Double
-- 1.844674407370955e19
--
maxWord64 :: Double
maxWord64 :: Double
maxWord64 = Double# -> Double
D# Double#
1.8446744073709552e19##
{-# INLINE maxWord64 #-}

{-# RULES
"fromRealFloat :: Double -> Word" fromRealFloat = fromDouble :: Double -> Word
"fromRealFloat :: Double -> Word64" fromRealFloat = fromDouble :: Double -> Word64
"fromRealFloat :: Float -> Word32" fromRealFloat = float2Word32
 #-}


-- | Values between @[0, 255]]@
instance Elevator Word8 where
  maxValue :: Word8
maxValue = Word8
forall a. Bounded a => a
maxBound
  minValue :: Word8
minValue = Word8
forall a. Bounded a => a
minBound
  fieldFormat :: Word8 -> FieldFormat
fieldFormat Word8
_ = FieldFormat
defFieldFormat {fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
3, fmtChar :: Char
fmtChar = Char
'd'}
  toWord8 :: Word8 -> Word8
toWord8 = Word8 -> Word8
forall a. a -> a
id
  {-# INLINE toWord8 #-}
  toWord16 :: Word8 -> Word16
toWord16 = Word8 -> Word16
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp
  {-# INLINE toWord16 #-}
  toWord32 :: Word8 -> Word32
toWord32 = Word8 -> Word32
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp
  {-# INLINE toWord32 #-}
  toWord64 :: Word8 -> Word64
toWord64 = Word8 -> Word64
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp
  {-# INLINE toWord64 #-}
  toFloat :: Word8 -> Float
toFloat = Word8 -> Float
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toFloat #-}
  toDouble :: Word8 -> Double
toDouble = Word8 -> Double
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toDouble #-}
  fromDouble :: Double -> Word8
fromDouble = Double -> Word8
forall e. Elevator e => e -> Word8
toWord8
  {-# INLINE fromDouble #-}
  toRealFloat :: Word8 -> a
toRealFloat = Word8 -> a
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Word8
fromRealFloat = a -> Word8
forall e. Elevator e => e -> Word8
toWord8
  {-# INLINE fromRealFloat #-}
  // :: Word8 -> Word8 -> Word8
(//) = Word8 -> Word8 -> Word8
forall a. Integral a => a -> a -> a
div
  {-# INLINE (//) #-}


-- | Values between @[0, 65535]]@
instance Elevator Word16 where
  maxValue :: Word16
maxValue = Word16
forall a. Bounded a => a
maxBound
  minValue :: Word16
minValue = Word16
forall a. Bounded a => a
minBound
  fieldFormat :: Word16 -> FieldFormat
fieldFormat Word16
_ = FieldFormat
defFieldFormat { fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
5, fmtChar :: Char
fmtChar = Char
'd'}
  toWord8 :: Word16 -> Word8
toWord8 = Word16 -> Word8
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown
  {-# INLINE toWord8 #-}
  toWord16 :: Word16 -> Word16
toWord16 = Word16 -> Word16
forall a. a -> a
id
  {-# INLINE toWord16 #-}
  toWord32 :: Word16 -> Word32
toWord32 = Word16 -> Word32
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp
  {-# INLINE toWord32 #-}
  toWord64 :: Word16 -> Word64
toWord64 = Word16 -> Word64
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp
  {-# INLINE toWord64 #-}
  toFloat :: Word16 -> Float
toFloat = Word16 -> Float
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toFloat #-}
  toDouble :: Word16 -> Double
toDouble = Word16 -> Double
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toDouble #-}
  fromDouble :: Double -> Word16
fromDouble = Double -> Word16
forall e. Elevator e => e -> Word16
toWord16
  {-# INLINE fromDouble #-}
  toRealFloat :: Word16 -> a
toRealFloat = Word16 -> a
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Word16
fromRealFloat = a -> Word16
forall e. Elevator e => e -> Word16
toWord16
  {-# INLINE fromRealFloat #-}
  // :: Word16 -> Word16 -> Word16
(//) = Word16 -> Word16 -> Word16
forall a. Integral a => a -> a -> a
div
  {-# INLINE (//) #-}


-- | Values between @[0, 4294967295]@
instance Elevator Word32 where
  maxValue :: Word32
maxValue = Word32
forall a. Bounded a => a
maxBound
  minValue :: Word32
minValue = Word32
forall a. Bounded a => a
minBound
  fieldFormat :: Word32 -> FieldFormat
fieldFormat Word32
_ = FieldFormat
defFieldFormat { fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
10, fmtChar :: Char
fmtChar = Char
'd'}
  toWord8 :: Word32 -> Word8
toWord8 = Word32 -> Word8
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown
  {-# INLINE toWord8 #-}
  toWord16 :: Word32 -> Word16
toWord16 = Word32 -> Word16
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown
  {-# INLINE toWord16 #-}
  toWord32 :: Word32 -> Word32
toWord32 = Word32 -> Word32
forall a. a -> a
id
  {-# INLINE toWord32 #-}
  toWord64 :: Word32 -> Word64
toWord64 = Word32 -> Word64
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp
  {-# INLINE toWord64 #-}
  toFloat :: Word32 -> Float
toFloat = Word32 -> Float
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toFloat #-}
  toDouble :: Word32 -> Double
toDouble = Word32 -> Double
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toDouble #-}
  fromDouble :: Double -> Word32
fromDouble = Double -> Word32
forall e. Elevator e => e -> Word32
toWord32
  {-# INLINE fromDouble #-}
  toRealFloat :: Word32 -> a
toRealFloat = Word32 -> a
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Word32
fromRealFloat = a -> Word32
forall e. Elevator e => e -> Word32
toWord32
  {-# INLINE fromRealFloat #-}
  // :: Word32 -> Word32 -> Word32
(//) = Word32 -> Word32 -> Word32
forall a. Integral a => a -> a -> a
div
  {-# INLINE (//) #-}


-- | Values between @[0, 18446744073709551615]@
instance Elevator Word64 where
  maxValue :: Word64
maxValue = Word64
forall a. Bounded a => a
maxBound
  minValue :: Word64
minValue = Word64
forall a. Bounded a => a
minBound
  fieldFormat :: Word64 -> FieldFormat
fieldFormat Word64
_ = FieldFormat
defFieldFormat { fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
20, fmtChar :: Char
fmtChar = Char
'd'}
  toWord8 :: Word64 -> Word8
toWord8 = Word64 -> Word8
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown
  {-# INLINE toWord8 #-}
  toWord16 :: Word64 -> Word16
toWord16 = Word64 -> Word16
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown
  {-# INLINE toWord16 #-}
  toWord32 :: Word64 -> Word32
toWord32 = Word64 -> Word32
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown
  {-# INLINE toWord32 #-}
  toWord64 :: Word64 -> Word64
toWord64 = Word64 -> Word64
forall a. a -> a
id
  {-# INLINE toWord64 #-}
  toFloat :: Word64 -> Float
toFloat = Word64 -> Float
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toFloat #-}
  toDouble :: Word64 -> Double
toDouble = Word64 -> Double
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toDouble #-}
  fromDouble :: Double -> Word64
fromDouble = Double -> Word64
double2Word64
  {-# INLINE fromDouble #-}
  toRealFloat :: Word64 -> a
toRealFloat = Word64 -> a
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Word64
fromRealFloat = a -> Word64
forall e. Elevator e => e -> Word64
toWord64
  {-# INLINE fromRealFloat #-}
  // :: Word64 -> Word64 -> Word64
(//) = Word64 -> Word64 -> Word64
forall a. Integral a => a -> a -> a
div
  {-# INLINE (//) #-}

-- | Values between @[0, 18446744073709551615]@ on 64bit
instance Elevator Word where
  maxValue :: Word
maxValue = Word
forall a. Bounded a => a
maxBound
  minValue :: Word
minValue = Word
forall a. Bounded a => a
minBound
#if WORD_SIZE_IN_BITS < 64
  fieldFormat :: Word -> FieldFormat
fieldFormat Word
_ = FieldFormat
defFieldFormat { fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
10, fmtChar :: Char
fmtChar = Char
'd'}
  toWord64 :: Word -> Word64
toWord64 = Word -> Word64
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown
  {-# INLINE toWord64 #-}
  fromDouble :: Double -> Word
fromDouble = Double -> Word
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE fromDouble #-}
#else
  fieldFormat _ = defFieldFormat { fmtWidth = Just 20, fmtChar = 'd'}
  toWord64 (W64# w#) = (W# w#)
  {-# INLINE toWord64 #-}
  fromDouble = toWord64 . double2Word64
  {-# INLINE fromDouble #-}
#endif
  toWord8 :: Word -> Word8
toWord8 = Word -> Word8
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown
  {-# INLINE toWord8 #-}
  toWord16 :: Word -> Word16
toWord16 = Word -> Word16
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown
  {-# INLINE toWord16 #-}
  toWord32 :: Word -> Word32
toWord32 = Word -> Word32
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown
  {-# INLINE toWord32 #-}
  toFloat :: Word -> Float
toFloat = Word -> Float
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toFloat #-}
  toDouble :: Word -> Double
toDouble = Word -> Double
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toDouble #-}
  toRealFloat :: Word -> a
toRealFloat = Word -> a
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Word
fromRealFloat = a -> Word
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE fromRealFloat #-}
  // :: Word -> Word -> Word
(//) = Word -> Word -> Word
forall a. Integral a => a -> a -> a
div
  {-# INLINE (//) #-}

-- | Values between @[0, 127]@
instance Elevator Int8 where
  maxValue :: Int8
maxValue = Int8
forall a. Bounded a => a
maxBound
  minValue :: Int8
minValue = Int8
0
  fieldFormat :: Int8 -> FieldFormat
fieldFormat Int8
_ = FieldFormat
defFieldFormat { fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
3, fmtChar :: Char
fmtChar = Char
'd'}
  toWord8 :: Int8 -> Word8
toWord8 = Int8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int8 -> Word8) -> (Int8 -> Int8) -> Int8 -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int8 -> Int8 -> Int8
forall a. Ord a => a -> a -> a
max Int8
0
  {-# INLINE toWord8 #-}
  toWord16 :: Int8 -> Word16
toWord16 = Int8 -> Word16
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp (Int8 -> Word16) -> (Int8 -> Int8) -> Int8 -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int8 -> Int8 -> Int8
forall a. Ord a => a -> a -> a
max Int8
0
  {-# INLINE toWord16 #-}
  toWord32 :: Int8 -> Word32
toWord32 = Int8 -> Word32
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp (Int8 -> Word32) -> (Int8 -> Int8) -> Int8 -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int8 -> Int8 -> Int8
forall a. Ord a => a -> a -> a
max Int8
0
  {-# INLINE toWord32 #-}
  toWord64 :: Int8 -> Word64
toWord64 = Int8 -> Word64
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp (Int8 -> Word64) -> (Int8 -> Int8) -> Int8 -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int8 -> Int8 -> Int8
forall a. Ord a => a -> a -> a
max Int8
0
  {-# INLINE toWord64 #-}
  toFloat :: Int8 -> Float
toFloat = Int8 -> Float
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1 (Int8 -> Float) -> (Int8 -> Int8) -> Int8 -> Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int8 -> Int8 -> Int8
forall a. Ord a => a -> a -> a
max Int8
0
  {-# INLINE toFloat #-}
  toRealFloat :: Int8 -> a
toRealFloat = Int8 -> a
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1 (Int8 -> a) -> (Int8 -> Int8) -> Int8 -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int8 -> Int8 -> Int8
forall a. Ord a => a -> a -> a
max Int8
0
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Int8
fromRealFloat = a -> Int8
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE fromRealFloat #-}
  // :: Int8 -> Int8 -> Int8
(//) = Int8 -> Int8 -> Int8
forall a. Integral a => a -> a -> a
div
  {-# INLINE (//) #-}


-- | Values between @[0, 32767]@
instance Elevator Int16 where
  maxValue :: Int16
maxValue = Int16
forall a. Bounded a => a
maxBound
  minValue :: Int16
minValue = Int16
0
  fieldFormat :: Int16 -> FieldFormat
fieldFormat Int16
_ = FieldFormat
defFieldFormat { fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
5, fmtChar :: Char
fmtChar = Char
'd'}
  toWord8 :: Int16 -> Word8
toWord8 = Int16 -> Word8
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown (Int16 -> Word8) -> (Int16 -> Int16) -> Int16 -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Int16 -> Int16
forall a. Ord a => a -> a -> a
max Int16
0
  {-# INLINE toWord8 #-}
  toWord16 :: Int16 -> Word16
toWord16 = Int16 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int16 -> Word16) -> (Int16 -> Int16) -> Int16 -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Int16 -> Int16
forall a. Ord a => a -> a -> a
max Int16
0
  {-# INLINE toWord16 #-}
  toWord32 :: Int16 -> Word32
toWord32 = Int16 -> Word32
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp (Int16 -> Word32) -> (Int16 -> Int16) -> Int16 -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Int16 -> Int16
forall a. Ord a => a -> a -> a
max Int16
0
  {-# INLINE toWord32 #-}
  toWord64 :: Int16 -> Word64
toWord64 = Int16 -> Word64
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp (Int16 -> Word64) -> (Int16 -> Int16) -> Int16 -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Int16 -> Int16
forall a. Ord a => a -> a -> a
max Int16
0
  {-# INLINE toWord64 #-}
  toFloat :: Int16 -> Float
toFloat = Int16 -> Float
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1 (Int16 -> Float) -> (Int16 -> Int16) -> Int16 -> Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Int16 -> Int16
forall a. Ord a => a -> a -> a
max Int16
0
  {-# INLINE toFloat #-}
  toRealFloat :: Int16 -> a
toRealFloat = Int16 -> a
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1 (Int16 -> a) -> (Int16 -> Int16) -> Int16 -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Int16 -> Int16
forall a. Ord a => a -> a -> a
max Int16
0
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Int16
fromRealFloat = a -> Int16
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE fromRealFloat #-}
  // :: Int16 -> Int16 -> Int16
(//) = Int16 -> Int16 -> Int16
forall a. Integral a => a -> a -> a
div
  {-# INLINE (//) #-}


-- | Values between @[0, 2147483647]@
instance Elevator Int32 where
  maxValue :: Int32
maxValue = Int32
forall a. Bounded a => a
maxBound
  minValue :: Int32
minValue = Int32
0
  fieldFormat :: Int32 -> FieldFormat
fieldFormat Int32
_ = FieldFormat
defFieldFormat { fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
10, fmtChar :: Char
fmtChar = Char
'd'}
  toWord8 :: Int32 -> Word8
toWord8 = Int32 -> Word8
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown (Int32 -> Word8) -> (Int32 -> Int32) -> Int32 -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int32 -> Int32
forall a. Ord a => a -> a -> a
max Int32
0
  {-# INLINE toWord8 #-}
  toWord16 :: Int32 -> Word16
toWord16 = Int32 -> Word16
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown (Int32 -> Word16) -> (Int32 -> Int32) -> Int32 -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int32 -> Int32
forall a. Ord a => a -> a -> a
max Int32
0
  {-# INLINE toWord16 #-}
  toWord32 :: Int32 -> Word32
toWord32 = Int32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32 -> Word32) -> (Int32 -> Int32) -> Int32 -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int32 -> Int32
forall a. Ord a => a -> a -> a
max Int32
0
  {-# INLINE toWord32 #-}
  toWord64 :: Int32 -> Word64
toWord64 = Int32 -> Word64
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
raiseUp (Int32 -> Word64) -> (Int32 -> Int32) -> Int32 -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int32 -> Int32
forall a. Ord a => a -> a -> a
max Int32
0
  {-# INLINE toWord64 #-}
  toFloat :: Int32 -> Float
toFloat = Int32 -> Float
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1 (Int32 -> Float) -> (Int32 -> Int32) -> Int32 -> Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int32 -> Int32
forall a. Ord a => a -> a -> a
max Int32
0
  {-# INLINE toFloat #-}
  toRealFloat :: Int32 -> a
toRealFloat = Int32 -> a
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1 (Int32 -> a) -> (Int32 -> Int32) -> Int32 -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int32 -> Int32
forall a. Ord a => a -> a -> a
max Int32
0
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Int32
fromRealFloat = a -> Int32
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE fromRealFloat #-}
  // :: Int32 -> Int32 -> Int32
(//) = Int32 -> Int32 -> Int32
forall a. Integral a => a -> a -> a
div
  {-# INLINE (//) #-}


-- | Values between @[0, 9223372036854775807]@
instance Elevator Int64 where
  maxValue :: Int64
maxValue = Int64
forall a. Bounded a => a
maxBound
  minValue :: Int64
minValue = Int64
0
  fieldFormat :: Int64 -> FieldFormat
fieldFormat Int64
_ = FieldFormat
defFieldFormat { fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
19, fmtChar :: Char
fmtChar = Char
'd'}
  toWord8 :: Int64 -> Word8
toWord8 = Int64 -> Word8
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown (Int64 -> Word8) -> (Int64 -> Int64) -> Int64 -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Int64 -> Int64
forall a. Ord a => a -> a -> a
max Int64
0
  {-# INLINE toWord8 #-}
  toWord16 :: Int64 -> Word16
toWord16 = Int64 -> Word16
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown (Int64 -> Word16) -> (Int64 -> Int64) -> Int64 -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Int64 -> Int64
forall a. Ord a => a -> a -> a
max Int64
0
  {-# INLINE toWord16 #-}
  toWord32 :: Int64 -> Word32
toWord32 = Int64 -> Word32
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown (Int64 -> Word32) -> (Int64 -> Int64) -> Int64 -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Int64 -> Int64
forall a. Ord a => a -> a -> a
max Int64
0
  {-# INLINE toWord32 #-}
  toWord64 :: Int64 -> Word64
toWord64 = Int64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Word64) -> (Int64 -> Int64) -> Int64 -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Int64 -> Int64
forall a. Ord a => a -> a -> a
max Int64
0
  {-# INLINE toWord64 #-}
  toFloat :: Int64 -> Float
toFloat = Int64 -> Float
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1 (Int64 -> Float) -> (Int64 -> Int64) -> Int64 -> Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Int64 -> Int64
forall a. Ord a => a -> a -> a
max Int64
0
  {-# INLINE toFloat #-}
  toRealFloat :: Int64 -> a
toRealFloat = Int64 -> a
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1 (Int64 -> a) -> (Int64 -> Int64) -> Int64 -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Int64 -> Int64
forall a. Ord a => a -> a -> a
max Int64
0
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Int64
fromRealFloat = a -> Int64
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE fromRealFloat #-}
  // :: Int64 -> Int64 -> Int64
(//) = Int64 -> Int64 -> Int64
forall a. Integral a => a -> a -> a
div
  {-# INLINE (//) #-}


-- | Values between @[0, 9223372036854775807]@ on 64bit
instance Elevator Int where
  maxValue :: Int
maxValue = Int
forall a. Bounded a => a
maxBound
  minValue :: Int
minValue = Int
0
#if WORD_SIZE_IN_BITS < 64
  fieldFormat :: Int -> FieldFormat
fieldFormat Int
_ = FieldFormat
defFieldFormat { fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
10, fmtChar :: Char
fmtChar = Char
'd'}
  toWord64 :: Int -> Word64
toWord64 = Int -> Word64
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown (Int -> Word64) -> (Int -> Int) -> Int -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0
  {-# INLINE toWord64 #-}
#else
  fieldFormat _ = defFieldFormat { fmtWidth = Just 19, fmtChar = 'd'}
  toWord64 = fromIntegral . max 0
  {-# INLINE toWord64 #-}
#endif
  toWord8 :: Int -> Word8
toWord8 = Int -> Word8
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown (Int -> Word8) -> (Int -> Int) -> Int -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0
  {-# INLINE toWord8 #-}
  toWord16 :: Int -> Word16
toWord16 = Int -> Word16
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown (Int -> Word16) -> (Int -> Int) -> Int -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0
  {-# INLINE toWord16 #-}
  toWord32 :: Int -> Word32
toWord32 = Int -> Word32
forall a b.
(Integral a, Bounded a, Integral b, Bounded b) =>
a -> b
dropDown (Int -> Word32) -> (Int -> Int) -> Int -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0
  {-# INLINE toWord32 #-}
  toFloat :: Int -> Float
toFloat = Int -> Float
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1 (Int -> Float) -> (Int -> Int) -> Int -> Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0
  {-# INLINE toFloat #-}
  toRealFloat :: Int -> a
toRealFloat = Int -> a
forall a b. (Fractional b, Integral a, Bounded a) => a -> b
squashTo1 (Int -> a) -> (Int -> Int) -> Int -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Int
fromRealFloat = a -> Int
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE fromRealFloat #-}
  // :: Int -> Int -> Int
(//) = Int -> Int -> Int
forall a. Integral a => a -> a -> a
div
  {-# INLINE (//) #-}


-- | Values between @[0.0, 1.0]@
instance Elevator Float where
  maxValue :: Float
maxValue = Float
1
  minValue :: Float
minValue = Float
0
  fieldFormat :: Float -> FieldFormat
fieldFormat Float
_ = FieldFormat
defFieldFormat { fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
11, fmtPrecision :: Maybe Int
fmtPrecision = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
8, fmtChar :: Char
fmtChar = Char
'f'}
  toWord8 :: Float -> Word8
toWord8 = Float -> Word8
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE toWord8 #-}
  toWord16 :: Float -> Word16
toWord16 = Float -> Word16
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE toWord16 #-}
  toWord32 :: Float -> Word32
toWord32 = Float -> Word32
float2Word32
  {-# INLINE toWord32 #-}
  toWord64 :: Float -> Word64
toWord64 = Float -> Word64
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE toWord64 #-}
  toFloat :: Float -> Float
toFloat = Float -> Float
forall a. a -> a
id
  {-# INLINE toFloat #-}
  toDouble :: Float -> Double
toDouble = Float -> Double
float2Double
  {-# INLINE toDouble #-}
  fromDouble :: Double -> Float
fromDouble = Double -> Float
forall e. Elevator e => e -> Float
toFloat
  {-# INLINE fromDouble #-}
  toRealFloat :: Float -> a
toRealFloat = (Integer -> Int -> a) -> (Integer, Int) -> a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat ((Integer, Int) -> a) -> (Float -> (Integer, Int)) -> Float -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Float
fromRealFloat = (Integer -> Int -> Float) -> (Integer, Int) -> Float
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Integer -> Int -> Float
forall a. RealFloat a => Integer -> Int -> a
encodeFloat ((Integer, Int) -> Float) -> (a -> (Integer, Int)) -> a -> Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat
  {-# INLINE fromRealFloat #-}
  // :: Float -> Float -> Float
(//) = Float -> Float -> Float
forall a. Fractional a => a -> a -> a
(/)
  {-# INLINE (//) #-}


-- | Values between @[0.0, 1.0]@
instance Elevator Double where
  maxValue :: Double
maxValue = Double
1
  minValue :: Double
minValue = Double
0
  fieldFormat :: Double -> FieldFormat
fieldFormat Double
_ = FieldFormat
defFieldFormat { fmtWidth :: Maybe Int
fmtWidth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
19, fmtPrecision :: Maybe Int
fmtPrecision = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
16, fmtChar :: Char
fmtChar = Char
'f' }
  toWord8 :: Double -> Word8
toWord8 = Double -> Word8
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE toWord8 #-}
  toWord16 :: Double -> Word16
toWord16 = Double -> Word16
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE toWord16 #-}
  toWord32 :: Double -> Word32
toWord32 = Double -> Word32
forall a b. (RealFloat a, Integral b, Bounded b) => a -> b
stretch
  {-# INLINE toWord32 #-}
  toWord64 :: Double -> Word64
toWord64 = Double -> Word64
double2Word64
  {-# INLINE toWord64 #-}
  toFloat :: Double -> Float
toFloat = Double -> Float
double2Float
  {-# INLINE toFloat #-}
  toDouble :: Double -> Double
toDouble = Double -> Double
forall a. a -> a
id
  {-# INLINE toDouble #-}
  fromDouble :: Double -> Double
fromDouble = Double -> Double
forall a. a -> a
id
  {-# INLINE fromDouble #-}
  toRealFloat :: Double -> a
toRealFloat = (Integer -> Int -> a) -> (Integer, Int) -> a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat ((Integer, Int) -> a) -> (Double -> (Integer, Int)) -> Double -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Double
fromRealFloat = (Integer -> Int -> Double) -> (Integer, Int) -> Double
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Integer -> Int -> Double
forall a. RealFloat a => Integer -> Int -> a
encodeFloat ((Integer, Int) -> Double) -> (a -> (Integer, Int)) -> a -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat
  {-# INLINE fromRealFloat #-}
  // :: Double -> Double -> Double
(//) = Double -> Double -> Double
forall a. Fractional a => a -> a -> a
(/)
  {-# INLINE (//) #-}

{-# RULES
"toRealFloat   :: Double -> Double / Float -> Float" toRealFloat = id
"toRealFloat   :: Double -> Float"                   toRealFloat = double2Float
"toRealFloat   :: Float -> Double"                   toRealFloat = float2Double
"fromRealFloat :: Double -> Double / Float -> Float" fromRealFloat = id
"fromRealFloat :: Double -> Float"                   fromRealFloat = double2Float
"fromRealFloat :: Float -> Double"                   fromRealFloat = float2Double
 #-}



-- | Discards imaginary part and changes precision of real part.
instance (PrintfArg e, Elevator e, RealFloat e) => Elevator (Complex e) where
  maxValue :: Complex e
maxValue = e
forall e. Elevator e => e
maxValue e -> e -> Complex e
forall a. a -> a -> Complex a
:+ e
forall e. Elevator e => e
maxValue
  minValue :: Complex e
minValue = e
forall e. Elevator e => e
minValue e -> e -> Complex e
forall a. a -> a -> Complex a
:+ e
forall e. Elevator e => e
minValue
  toShowS :: Complex e -> ShowS
toShowS (e
r :+ e
i) = e -> ShowS
forall e. Elevator e => e -> ShowS
toShowS e
r ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> FieldFormatter
forall a. PrintfArg a => a -> FieldFormatter
formatArg e
i ((e -> FieldFormat
forall e. Elevator e => e -> FieldFormat
fieldFormat e
i) {fmtSign :: Maybe FormatSign
fmtSign = FormatSign -> Maybe FormatSign
forall a. a -> Maybe a
Just FormatSign
SignPlus}) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char
'i' Char -> ShowS
forall a. a -> [a] -> [a]
:)
  toWord8 :: Complex e -> Word8
toWord8 = e -> Word8
forall e. Elevator e => e -> Word8
toWord8 (e -> Word8) -> (Complex e -> e) -> Complex e -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Complex e -> e
forall a. Complex a -> a
realPart
  {-# INLINE toWord8 #-}
  toWord16 :: Complex e -> Word16
toWord16 = e -> Word16
forall e. Elevator e => e -> Word16
toWord16 (e -> Word16) -> (Complex e -> e) -> Complex e -> Word16
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Complex e -> e
forall a. Complex a -> a
realPart
  {-# INLINE toWord16 #-}
  toWord32 :: Complex e -> Word32
toWord32 = e -> Word32
forall e. Elevator e => e -> Word32
toWord32 (e -> Word32) -> (Complex e -> e) -> Complex e -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Complex e -> e
forall a. Complex a -> a
realPart
  {-# INLINE toWord32 #-}
  toWord64 :: Complex e -> Word64
toWord64 = e -> Word64
forall e. Elevator e => e -> Word64
toWord64 (e -> Word64) -> (Complex e -> e) -> Complex e -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Complex e -> e
forall a. Complex a -> a
realPart
  {-# INLINE toWord64 #-}
  toFloat :: Complex e -> Float
toFloat = e -> Float
forall e. Elevator e => e -> Float
toFloat (e -> Float) -> (Complex e -> e) -> Complex e -> Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Complex e -> e
forall a. Complex a -> a
realPart
  {-# INLINE toFloat #-}
  toDouble :: Complex e -> Double
toDouble = e -> Double
forall e. Elevator e => e -> Double
toDouble (e -> Double) -> (Complex e -> e) -> Complex e -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Complex e -> e
forall a. Complex a -> a
realPart
  {-# INLINE toDouble #-}
  fromDouble :: Double -> Complex e
fromDouble = (e -> e -> Complex e
forall a. a -> a -> Complex a
:+ e
0) (e -> Complex e) -> (Double -> e) -> Double -> Complex e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> e
forall e. Elevator e => Double -> e
fromDouble
  {-# INLINE fromDouble #-}
  toRealFloat :: Complex e -> a
toRealFloat = e -> a
forall e a. (Elevator e, Elevator a, RealFloat a) => e -> a
toRealFloat (e -> a) -> (Complex e -> e) -> Complex e -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Complex e -> e
forall a. Complex a -> a
realPart
  {-# INLINE toRealFloat #-}
  fromRealFloat :: a -> Complex e
fromRealFloat = (e -> e -> Complex e
forall a. a -> a -> Complex a
:+ e
0) (e -> Complex e) -> (a -> e) -> a -> Complex e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> e
forall e a. (Elevator e, Elevator a, RealFloat a) => a -> e
fromRealFloat
  {-# INLINE fromRealFloat #-}
  // :: Complex e -> Complex e -> Complex e
(//) = Complex e -> Complex e -> Complex e
forall a. Fractional a => a -> a -> a
(/)
  {-# INLINE (//) #-}