egison-2.0.3: An Interpreter for the Programming Language Egison

Safe HaskellSafe-Inferred
LanguageHaskell98

Language.Egison.Numerical

Synopsis

Documentation

unpackBool :: EgisonVal -> ThrowsError Bool Source

Convert a number to a string; radix is optional, defaults to base 10 numToString :: [EgisonVal] -> IOThrowsError EgisonVal numToString [(Number n), (Number radix)] = do case radix of 2 -> do -- Nice tip from StackOverflow question #1959715 liftIO $ stringToCharCollection $ showIntAtBase 2 intToDigit n "" 8 -> liftIO $ stringToCharCollection $ printf "%o" n 10 -> liftIO $ stringToCharCollection $ printf "%d" n 16 -> liftIO $ stringToCharCollection $ printf "%x" n _ -> throwError $ BadSpecialForm "Invalid radix value" $ Number radix

Convert a float to a string; radix is optional, defaults to base 10 floatToString :: [EgisonVal] -> IOThrowsError EgisonVal floatToString [(Float n)] = liftIO $ stringToCharCollection $ show n floatToString [x] = throwError $ TypeMismatch "number" x floatToString badArgList = throwError $ NumArgs 1 badArgList

Extract an integer from the given value, throwing a type error if the wrong type is passed.

unpackNum :: EgisonVal -> ThrowsError Integer Source

Extract an integer from the given value, throwing a type error if the wrong type is passed.

unpackFloat :: EgisonVal -> ThrowsError Double Source

Extract an double from the given value, throwing a type error if the wrong type is passed.