File: FFI.hs

package info (click to toggle)
haskell-double-conversion 2.0.5.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: haskell: 611; cpp: 340; ansic: 31; makefile: 6
file content (125 lines) | stat: -rw-r--r-- 5,246 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{-# LANGUAGE CPP, ForeignFunctionInterface, MagicHash, TypeFamilies,
             UnliftedFFITypes #-}

-- |
-- Module      : Data.Double.Conversion.FFI
-- Copyright   : (c) 2011 MailRank, Inc.
--
-- License     : BSD-style
-- Maintainer  : bos@serpentine.com
-- Stability   : experimental
-- Portability : GHC
--
-- FFI interface support for converting between
-- floating point values and text.

module Data.Double.Conversion.Internal.FFI
    (
      ForeignFloating
    , c_Text_ToExponential
    , c_Text_ToExponentialFloat
    , c_Text_ToFixed
    , c_Text_ToFixedFloat
    , c_Text_ToPrecision
    , c_Text_ToPrecisionFloat
    , c_Text_ToShortest
    , c_Text_ToShortestFloat
    , c_ToExponentialLength
    , c_ToFixedLength
    , c_ToPrecisionLength
    , c_ToShortestLength
    , c_ToExponential
    , c_ToExponentialFloat
    , c_ToFixed
    , c_ToFixedFloat
    , c_ToPrecision
    , c_ToPrecisionFloat
    , c_ToShortest
    , c_ToShortestFloat
    ) where

import Data.Word (Word8)
#if __GLASGOW_HASKELL__ >= 703
import Foreign.C.Types (CDouble(CDouble), CFloat(CFloat), CInt(CInt))
#else
import Foreign.C.Types (CDouble, CFloat, CInt)
#endif
import Foreign.Ptr (Ptr)
import GHC.Prim (MutableByteArray#)

type family ForeignFloating h :: *

type instance ForeignFloating Double = CDouble
type instance ForeignFloating Float = CFloat

foreign import ccall unsafe "hs-double-conversion.h _hs_ToShortestLength"
    c_ToShortestLength :: CInt

foreign import ccall unsafe "hs-double-conversion.h _hs_ToShortest"
    c_ToShortest :: CDouble -> Ptr Word8 -> IO CInt

foreign import ccall unsafe "hs-double-conversion.h _hs_ToShortestFloat"
    c_ToShortestFloat :: CFloat -> Ptr Word8 -> IO CInt

foreign import ccall unsafe "hs-double-conversion.h _hs_ToFixedLength"
    c_ToFixedLength :: CInt

foreign import ccall unsafe "hs-double-conversion.h _hs_ToFixed"
    c_ToFixed :: CDouble -> Ptr Word8 -> CInt -> IO CInt

foreign import ccall unsafe "hs-double-conversion.h _hs_ToFixedFloat"
    c_ToFixedFloat :: CFloat -> Ptr Word8 -> CInt -> IO CInt

foreign import ccall unsafe "hs-double-conversion.h _hs_ToExponentialLength"
    c_ToExponentialLength :: CInt

foreign import ccall unsafe "hs-double-conversion.h _hs_ToExponential"
    c_ToExponential :: CDouble -> Ptr Word8 -> CInt -> IO CInt

foreign import ccall unsafe "hs-double-conversion.h _hs_ToExponentialFloat"
    c_ToExponentialFloat :: CFloat -> Ptr Word8 -> CInt -> IO CInt

foreign import ccall unsafe "hs-double-conversion.h _hs_ToPrecisionLength"
    c_ToPrecisionLength :: CInt

foreign import ccall unsafe "hs-double-conversion.h _hs_ToPrecision"
    c_ToPrecision :: CDouble -> Ptr Word8 -> CInt -> IO CInt

foreign import ccall unsafe "hs-double-conversion.h _hs_ToPrecisionFloat"
    c_ToPrecisionFloat :: CFloat -> Ptr Word8 -> CInt -> IO CInt

#if MIN_VERSION_text(2,0,0)
foreign import ccall unsafe "hs-double-conversion.h _hs_ToShortest"
    c_Text_ToShortest :: CDouble -> MutableByteArray# s -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_ToShortestFloat"
    c_Text_ToShortestFloat :: CFloat -> MutableByteArray# s -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_ToFixed"
    c_Text_ToFixed :: CDouble -> MutableByteArray# s -> CInt -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_ToFixedFloat"
    c_Text_ToFixedFloat :: CFloat -> MutableByteArray# s-> CInt -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_ToExponential"
    c_Text_ToExponential :: CDouble -> MutableByteArray# s -> CInt -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_ToExponentialFloat"
    c_Text_ToExponentialFloat :: CFloat -> MutableByteArray# s -> CInt -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_ToPrecision"
    c_Text_ToPrecision :: CDouble -> MutableByteArray# s -> CInt -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_ToPrecisionFloat"
    c_Text_ToPrecisionFloat :: CFloat -> MutableByteArray# s -> CInt -> IO CInt
#else
foreign import ccall unsafe "hs-double-conversion.h _hs_Text_ToShortest"
    c_Text_ToShortest :: CDouble -> MutableByteArray# s -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_Text_ToShortestFloat"
    c_Text_ToShortestFloat :: CFloat -> MutableByteArray# s -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_Text_ToFixed"
    c_Text_ToFixed :: CDouble -> MutableByteArray# s -> CInt -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_Text_ToFixedFloat"
    c_Text_ToFixedFloat :: CFloat -> MutableByteArray# s -> CInt -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_Text_ToExponential"
    c_Text_ToExponential :: CDouble -> MutableByteArray# s -> CInt -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_Text_ToExponentialFloat"
    c_Text_ToExponentialFloat :: CFloat -> MutableByteArray# s -> CInt -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_Text_ToPrecision"
    c_Text_ToPrecision :: CDouble -> MutableByteArray# s -> CInt -> IO CInt
foreign import ccall unsafe "hs-double-conversion.h _hs_Text_ToPrecisionFloat"
    c_Text_ToPrecisionFloat :: CFloat -> MutableByteArray# s -> CInt -> IO CInt
#endif