quantile :: (RealFrac a) => a -> [a] -> a
quantile q xs | isWhole l = 0.5 * ((xs !! (round l - 1)) + xs !! round l)
              | otherwise = xs !! (ceiling l - 1)
    where numXs     = length xs
          l         = fromIntegral numXs * q
          isWhole x = x == fromInteger (round x)


-- | Gets the median from a list of values.
quantile :: (RealFrac a) => a -> [a] -> a
quantile q xs | isWhole l = 0.5 * ((xs !! (round l - 1)) + xs !! round l)
              | otherwise = xs !! (ceiling l - 1)
    where numXs     = length xs
          l         = fromIntegral numXs * q
          isWhole x = x == fromInteger (round x)


-- | Gets the median from a list of values.
quantile q xs | isWhole l = 0.5 * ((xs !! (round l - 1)) + xs !! round l)
              | otherwise = xs !! (ceiling l - 1)
    where numXs     = length xs
          l         = fromIntegral numXs * q
          isWhole x = x == fromInteger (round x)


-- | Gets the median from a list of values.