Created
April 14, 2013 05:27
-
-
Save kini/5381567 to your computer and use it in GitHub Desktop.
A function for computing non-integer representations ( http://en.wikipedia.org/wiki/Non-integer_representation )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | baserep base num digits = (mantissa, exponent) | |
baserep :: (RealFrac a) => a -> a -> Int -> ([Int], Int) | |
baserep _ _ 0 = ([], 0) | |
baserep base num digits | |
| num < 0 = undefined | |
| num >= base = let (x, y) = baserep base (num / base) digits in (x, y+1) | |
| otherwise = let d = fromIntegral (floor num) | |
(x, y) = baserep base ((num - fromIntegral d) * base) (digits - 1) | |
in (d : x, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment