module Data.Number.Flint.NF.Fmpzi.Instances where import System.IO.Unsafe import Foreign.C.String import Foreign.Marshal.Alloc ( free ) import Data.Number.Flint.NF.Fmpzi instance Show Fmpzi where show :: Fmpzi -> String show Fmpzi x = IO String -> String forall a. IO a -> a unsafePerformIO (IO String -> String) -> IO String -> String forall a b. (a -> b) -> a -> b $ do (Fmpzi _, CString cs) <- Fmpzi -> (Ptr CFmpzi -> IO CString) -> IO (Fmpzi, CString) forall {a}. Fmpzi -> (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) withFmpzi Fmpzi x Ptr CFmpzi -> IO CString fmpzi_get_str String s <- CString -> IO String peekCString CString cs CString -> IO () forall a. Ptr a -> IO () free CString cs String -> IO String forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return String s instance Eq Fmpzi where == :: Fmpzi -> Fmpzi -> Bool (==) Fmpzi x Fmpzi y = (Fmpzi, Bool) -> Bool forall a b. (a, b) -> b snd ((Fmpzi, Bool) -> Bool) -> (Fmpzi, Bool) -> Bool forall a b. (a -> b) -> a -> b $ (Fmpzi, (Fmpzi, Bool)) -> (Fmpzi, Bool) forall a b. (a, b) -> b snd ((Fmpzi, (Fmpzi, Bool)) -> (Fmpzi, Bool)) -> (Fmpzi, (Fmpzi, Bool)) -> (Fmpzi, Bool) forall a b. (a -> b) -> a -> b $ IO (Fmpzi, (Fmpzi, Bool)) -> (Fmpzi, (Fmpzi, Bool)) forall a. IO a -> a unsafePerformIO (IO (Fmpzi, (Fmpzi, Bool)) -> (Fmpzi, (Fmpzi, Bool))) -> IO (Fmpzi, (Fmpzi, Bool)) -> (Fmpzi, (Fmpzi, Bool)) forall a b. (a -> b) -> a -> b $ Fmpzi -> (Ptr CFmpzi -> IO (Fmpzi, Bool)) -> IO (Fmpzi, (Fmpzi, Bool)) forall {a}. Fmpzi -> (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) withFmpzi Fmpzi x ((Ptr CFmpzi -> IO (Fmpzi, Bool)) -> IO (Fmpzi, (Fmpzi, Bool))) -> (Ptr CFmpzi -> IO (Fmpzi, Bool)) -> IO (Fmpzi, (Fmpzi, Bool)) forall a b. (a -> b) -> a -> b $ \Ptr CFmpzi x -> Fmpzi -> (Ptr CFmpzi -> IO Bool) -> IO (Fmpzi, Bool) forall {a}. Fmpzi -> (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) withFmpzi Fmpzi y ((Ptr CFmpzi -> IO Bool) -> IO (Fmpzi, Bool)) -> (Ptr CFmpzi -> IO Bool) -> IO (Fmpzi, Bool) forall a b. (a -> b) -> a -> b $ \Ptr CFmpzi y -> do CInt result <- Ptr CFmpzi -> Ptr CFmpzi -> IO CInt fmpzi_equal Ptr CFmpzi x Ptr CFmpzi y Bool -> IO Bool forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return (Bool -> IO Bool) -> Bool -> IO Bool forall a b. (a -> b) -> a -> b $ CInt result CInt -> CInt -> Bool forall a. Eq a => a -> a -> Bool == CInt 1 instance Num Fmpzi where {-# INLINE (+) #-} + :: Fmpzi -> Fmpzi -> Fmpzi (+) = (Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO ()) -> Fmpzi -> Fmpzi -> Fmpzi forall {a}. (Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO a) -> Fmpzi -> Fmpzi -> Fmpzi lift2 Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO () fmpzi_add {-# INLINE (-) #-} (-) = (Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO ()) -> Fmpzi -> Fmpzi -> Fmpzi forall {a}. (Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO a) -> Fmpzi -> Fmpzi -> Fmpzi lift2 Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO () fmpzi_sub {-# INLINE (*) #-} * :: Fmpzi -> Fmpzi -> Fmpzi (*) = (Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO ()) -> Fmpzi -> Fmpzi -> Fmpzi forall {a}. (Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO a) -> Fmpzi -> Fmpzi -> Fmpzi lift2 Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO () fmpzi_mul negate :: Fmpzi -> Fmpzi negate = (Ptr CFmpzi -> Ptr CFmpzi -> IO ()) -> Fmpzi -> Fmpzi forall {a}. (Ptr CFmpzi -> Ptr CFmpzi -> IO a) -> Fmpzi -> Fmpzi lift1 Ptr CFmpzi -> Ptr CFmpzi -> IO () fmpzi_neg abs :: Fmpzi -> Fmpzi abs = Fmpzi -> Fmpzi forall a. HasCallStack => a undefined fromInteger :: Integer -> Fmpzi fromInteger Integer x = IO Fmpzi -> Fmpzi forall a. IO a -> a unsafePerformIO (IO Fmpzi -> Fmpzi) -> IO Fmpzi -> Fmpzi forall a b. (a -> b) -> a -> b $ do Fmpzi result <- IO Fmpzi newFmpzi Fmpzi -> (Ptr CFmpzi -> IO ()) -> IO (Fmpzi, ()) forall {a}. Fmpzi -> (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) withFmpzi Fmpzi result ((Ptr CFmpzi -> IO ()) -> IO (Fmpzi, ())) -> (Ptr CFmpzi -> IO ()) -> IO (Fmpzi, ()) forall a b. (a -> b) -> a -> b $ \Ptr CFmpzi result -> do Ptr CFmpzi -> CLong -> CLong -> IO () fmpzi_set_si_si Ptr CFmpzi result (Integer -> CLong forall a. Num a => Integer -> a fromInteger Integer x) CLong 1 Fmpzi -> IO Fmpzi forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return Fmpzi result signum :: Fmpzi -> Fmpzi signum = Fmpzi -> Fmpzi forall a. HasCallStack => a undefined lift1 :: (Ptr CFmpzi -> Ptr CFmpzi -> IO a) -> Fmpzi -> Fmpzi lift1 Ptr CFmpzi -> Ptr CFmpzi -> IO a f Fmpzi x = (Fmpzi, (Fmpzi, a)) -> Fmpzi forall a b. (a, b) -> a fst ((Fmpzi, (Fmpzi, a)) -> Fmpzi) -> (Fmpzi, (Fmpzi, a)) -> Fmpzi forall a b. (a -> b) -> a -> b $ IO (Fmpzi, (Fmpzi, a)) -> (Fmpzi, (Fmpzi, a)) forall a. IO a -> a unsafePerformIO (IO (Fmpzi, (Fmpzi, a)) -> (Fmpzi, (Fmpzi, a))) -> IO (Fmpzi, (Fmpzi, a)) -> (Fmpzi, (Fmpzi, a)) forall a b. (a -> b) -> a -> b $ (Ptr CFmpzi -> IO (Fmpzi, a)) -> IO (Fmpzi, (Fmpzi, a)) forall {a}. (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) withNewFmpzi ((Ptr CFmpzi -> IO (Fmpzi, a)) -> IO (Fmpzi, (Fmpzi, a))) -> (Ptr CFmpzi -> IO (Fmpzi, a)) -> IO (Fmpzi, (Fmpzi, a)) forall a b. (a -> b) -> a -> b $ \Ptr CFmpzi result -> Fmpzi -> (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) forall {a}. Fmpzi -> (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) withFmpzi Fmpzi x ((Ptr CFmpzi -> IO a) -> IO (Fmpzi, a)) -> (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) forall a b. (a -> b) -> a -> b $ \Ptr CFmpzi x -> Ptr CFmpzi -> Ptr CFmpzi -> IO a f Ptr CFmpzi result Ptr CFmpzi x lift2 :: (Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO a) -> Fmpzi -> Fmpzi -> Fmpzi lift2 Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO a f Fmpzi x Fmpzi y = (Fmpzi, (Fmpzi, (Fmpzi, a))) -> Fmpzi forall a b. (a, b) -> a fst ((Fmpzi, (Fmpzi, (Fmpzi, a))) -> Fmpzi) -> (Fmpzi, (Fmpzi, (Fmpzi, a))) -> Fmpzi forall a b. (a -> b) -> a -> b $ IO (Fmpzi, (Fmpzi, (Fmpzi, a))) -> (Fmpzi, (Fmpzi, (Fmpzi, a))) forall a. IO a -> a unsafePerformIO (IO (Fmpzi, (Fmpzi, (Fmpzi, a))) -> (Fmpzi, (Fmpzi, (Fmpzi, a)))) -> IO (Fmpzi, (Fmpzi, (Fmpzi, a))) -> (Fmpzi, (Fmpzi, (Fmpzi, a))) forall a b. (a -> b) -> a -> b $ (Ptr CFmpzi -> IO (Fmpzi, (Fmpzi, a))) -> IO (Fmpzi, (Fmpzi, (Fmpzi, a))) forall {a}. (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) withNewFmpzi ((Ptr CFmpzi -> IO (Fmpzi, (Fmpzi, a))) -> IO (Fmpzi, (Fmpzi, (Fmpzi, a)))) -> (Ptr CFmpzi -> IO (Fmpzi, (Fmpzi, a))) -> IO (Fmpzi, (Fmpzi, (Fmpzi, a))) forall a b. (a -> b) -> a -> b $ \Ptr CFmpzi result -> Fmpzi -> (Ptr CFmpzi -> IO (Fmpzi, a)) -> IO (Fmpzi, (Fmpzi, a)) forall {a}. Fmpzi -> (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) withFmpzi Fmpzi x ((Ptr CFmpzi -> IO (Fmpzi, a)) -> IO (Fmpzi, (Fmpzi, a))) -> (Ptr CFmpzi -> IO (Fmpzi, a)) -> IO (Fmpzi, (Fmpzi, a)) forall a b. (a -> b) -> a -> b $ \Ptr CFmpzi x -> Fmpzi -> (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) forall {a}. Fmpzi -> (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) withFmpzi Fmpzi y ((Ptr CFmpzi -> IO a) -> IO (Fmpzi, a)) -> (Ptr CFmpzi -> IO a) -> IO (Fmpzi, a) forall a b. (a -> b) -> a -> b $ \Ptr CFmpzi y -> Ptr CFmpzi -> Ptr CFmpzi -> Ptr CFmpzi -> IO a f Ptr CFmpzi result Ptr CFmpzi x Ptr CFmpzi y