module Text.Show.Text.Data.Ratio (showbRatioPrec) where
import Data.Text.Lazy.Builder (Builder)
import Data.Ratio (Ratio, numerator, denominator)
import GHC.Real (ratioPrec, ratioPrec1)
import Prelude hiding (Show)
import Text.Show.Text.Classes (Show(showbPrec), showbParen)
import Text.Show.Text.Data.Integral ()
import Text.Show.Text.Utils ((<>))
#include "inline.h"
showbRatioPrec :: (Show a, Integral a) => Int -> Ratio a -> Builder
showbRatioPrec p q = showbParen (p > ratioPrec) $
showbPrec ratioPrec1 (numerator q)
<> " % "
<> showbPrec ratioPrec1 (denominator q)
instance (Show a, Integral a) => Show (Ratio a) where
showbPrec = showbRatioPrec
INLINE_INST_FUN(showbPrec)