module ELynx.Tools.Numeric
(
harmonic,
roundN,
)
where
harmonic :: Int -> Double
harmonic :: Int -> Double
harmonic Int
1 = Double
1.0
harmonic Int
n = Double
1.0 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Int -> Double
harmonic (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
roundN :: Int -> Double -> Double
roundN :: Int -> Double -> Double
roundN Int
n Double
v = Integer -> Double
forall a. Num a => Integer -> a
fromInteger (Double -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
round (Double -> Integer) -> Double -> Integer
forall a b. (a -> b) -> a -> b
$ Double
v Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
10 Double -> Int -> Double
forall a b. (Num a, Integral b) => a -> b -> a
^ Int
n)) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
10.0 Double -> Int -> Double
forall a b. (Fractional a, Integral b) => a -> b -> a
^^ Int
n)