-- GENERATED by C->Haskell Compiler, version 0.17.2 Crystal Seed, 24 Jan 2009 (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           Prelude hiding (Float)

import           CPython.Internal

newtype Float = Float (ForeignPtr Float)

instance Object Float where
	toObject (Float x) = SomeObject x
	fromForeignPtr = Float

instance Concrete Float where
	concreteType _ = floatType

floatType :: (Type)
floatType =
  unsafePerformIO $
  let {res = floatType'_} in
  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'_ :: (Ptr ())

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

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