doubleToWords :: DynFlags -> Rational -> [CmmLit]
doubleToWords dflags r
  | big_doubles dflags                  -- doubles are 2 words
  = runST (do
        arr <- newArray_ ((0::Int),1)
        writeArray arr 0 (fromRational r)
        arr' <- castDoubleToIntArray arr
        i1 <- readArray arr' 0
        i2 <- readArray arr' 1
        return [ CmmInt (toInteger i1) (wordWidth dflags)
               , CmmInt (toInteger i2) (wordWidth dflags)
               ]
    )
  | otherwise                           -- doubles are 1 word
  = runST (do
        arr <- newArray_ ((0::Int),0)
        writeArray arr 0 (fromRational r)
        arr' <- castDoubleToIntArray arr
        i <- readArray arr' 0
        return [ CmmInt (toInteger i) (wordWidth dflags) ]
    )
doubleToWords :: DynFlags -> Rational -> [CmmLit]
doubleToWords dflags r
  | big_doubles dflags                  -- doubles are 2 words
  = runST (do
        arr <- newArray_ ((0::Int),1)
        writeArray arr 0 (fromRational r)
        arr' <- castDoubleToIntArray arr
        i1 <- readArray arr' 0
        i2 <- readArray arr' 1
        return [ CmmInt (toInteger i1) (wordWidth dflags)
               , CmmInt (toInteger i2) (wordWidth dflags)
               ]
    )
  | otherwise                           -- doubles are 1 word
  = runST (do
        arr <- newArray_ ((0::Int),0)
        writeArray arr 0 (fromRational r)
        arr' <- castDoubleToIntArray arr
        i <- readArray arr' 0
        return [ CmmInt (toInteger i) (wordWidth dflags) ]
    )
doubleToWords dflags r
  | big_doubles dflags                  -- doubles are 2 words
  = runST (do
        arr <- newArray_ ((0::Int),1)
        writeArray arr 0 (fromRational r)
        arr' <- castDoubleToIntArray arr
        i1 <- readArray arr' 0
        i2 <- readArray arr' 1
        return [ CmmInt (toInteger i1) (wordWidth dflags)
               , CmmInt (toInteger i2) (wordWidth dflags)
               ]
    )
  | otherwise                           -- doubles are 1 word
  = runST (do
        arr <- newArray_ ((0::Int),0)
        writeArray arr 0 (fromRational r)
        arr' <- castDoubleToIntArray arr
        i <- readArray arr' 0
        return [ CmmInt (toInteger i) (wordWidth dflags) ]
    )