rev-scientific-0.1.0.0: Data/ReversedScientific.hs
-- |
-- Module : Data.ReversedScientific
-- Copyright : (c) OleksandrZhabenko 2023
-- License : MIT
-- Stability : Experimental
-- Maintainer : oleksandr.zhabenko@yahoo.com
--
-- Provides a function that shows the somewhat "reversed" scientific notation of the big 'Integer' number so that it is easier (more likely exact) to compare at quick glance twe numbers in such a notation by their order and values.
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_HADDOCK -show-extensions #-}
module Data.ReversedScientific where
import GHC.Base
import GHC.Num ((-),Integer)
import Text.Show (Show(..))
import Data.List (length,dropWhileEnd)
showBignum :: Int -> Integer -> String
showBignum n x
| l0 < 6 = xShow
| l >= n = mconcat ["e", show (l - 1), "~m", show l0, "~", k1s, ".", k2s, "...", k3s]
| otherwise = xShow
where xShow = show x
l = length xShow
k = dropWhileEnd (== '0') xShow
l0 = length k
f (p:q:r:s:t:u:v:vs) = f (p:q:r:t:u:v:vs)
f (p:q:r:s:t:u:_) = ([p], [q, r], [s, t, u])
(k1s,k2s,k3s) = f k