-- GENERATED by C->Haskell Compiler, version 0.28.7 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "lib/CPython/Types/Float.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}

-- Copyright (C) 2009 John Millikin <jmillikin@gmail.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.

module CPython.Types.Float
  ( Float
  , floatType
  , toFloat
  , fromFloat
  ) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified System.IO.Unsafe as C2HSImp





import           Prelude hiding (Float)

import           CPython.Internal

newtype Float = Float (ForeignPtr Float)

instance Object Float where
  toObject :: Float -> SomeObject
toObject (Float x :: ForeignPtr Float
x) = ForeignPtr Float -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr Float
x
  fromForeignPtr :: ForeignPtr Float -> Float
fromForeignPtr = ForeignPtr Float -> Float
Float

instance Concrete Float where
  concreteType :: Float -> Type
concreteType _ = Type
floatType

floatType :: (Type)
floatType =
  C2HSImp.unsafePerformIO $
  floatType'_ >>= \res ->
  peekStaticObject res >>= \res' ->
  return (res')

{-# LINE 41 "lib/CPython/Types/Float.chs" #-}


toFloat :: (Double) -> IO ((Float))
toFloat a1 =
  let {a1' = realToFrac a1} in 
  toFloat'_ a1' >>= \res ->
  stealObject res >>= \res' ->
  return (res')

{-# LINE 45 "lib/CPython/Types/Float.chs" #-}


fromFloat :: (Float) -> IO ((Double))
fromFloat a1 =
  withObject a1 $ \a1' -> 
  fromFloat'_ a1' >>= \res ->
  let {res' = realToFrac res} in
  return (res')

{-# LINE 49 "lib/CPython/Types/Float.chs" #-}


foreign import ccall unsafe "CPython/Types/Float.chs.h hscpython_PyFloat_Type"
  floatType'_ :: (IO (C2HSImp.Ptr ()))

foreign import ccall safe "CPython/Types/Float.chs.h PyFloat_FromDouble"
  toFloat'_ :: (C2HSImp.CDouble -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "CPython/Types/Float.chs.h PyFloat_AsDouble"
  fromFloat'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CDouble))