{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE MagicHash #-}
module Numeric.LongDouble.X87_128
(
LongDouble(..)
, truncate'
, round'
, ceiling'
, floor'
, fromDouble
, toDouble
, fromInt
, toInt
) where
import Data.Bits (bit, testBit, (.&.), shiftL, shiftR)
import Data.Ratio ((%), numerator, denominator)
import Data.Word (Word64)
import Foreign (Ptr, castPtr, with, alloca)
import Foreign.C.Types (CIntMax(..), CInt(..), CDouble(..))
import Foreign.Storable (Storable(..))
import Numeric (showFloat, readFloat, readSigned)
import System.IO.Unsafe (unsafePerformIO)
import GHC.Exts (Int(..))
import GHC.Integer.Logarithms (integerLog2#)
data LongDouble = LD !Word64 !Word64
instance Storable LongDouble where
sizeOf :: LongDouble -> Int
sizeOf LongDouble
_ = Int
2 forall a. Num a => a -> a -> a
* forall a. Storable a => a -> Int
sizeOf (Word64
0 :: Word64)
alignment :: LongDouble -> Int
alignment LongDouble
_ = forall a. Storable a => a -> Int
alignment (Word64
0 :: Word64)
peek :: Ptr LongDouble -> IO LongDouble
peek Ptr LongDouble
p = do
let q :: Ptr Word64
q :: Ptr Word64
q = forall a b. Ptr a -> Ptr b
castPtr Ptr LongDouble
p
Word64
a <- forall a. Storable a => Ptr a -> Int -> IO a
peekElemOff Ptr Word64
q Int
0
Word64
b <- forall a. Storable a => Ptr a -> Int -> IO a
peekElemOff Ptr Word64
q Int
1
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Word64 -> Word64 -> LongDouble
LD Word64
a Word64
b
poke :: Ptr LongDouble -> LongDouble -> IO ()
poke Ptr LongDouble
p (LD Word64
a Word64
b) = do
let q :: Ptr Word64
q :: Ptr Word64
q = forall a b. Ptr a -> Ptr b
castPtr Ptr LongDouble
p
forall a. Storable a => Ptr a -> Int -> a -> IO ()
pokeElemOff Ptr Word64
q Int
0 Word64
a
forall a. Storable a => Ptr a -> Int -> a -> IO ()
pokeElemOff Ptr Word64
q Int
1 Word64
b
#include "X87.hs"