module Sound.Sc3.Common.Math where
import qualified Data.Fixed
import Data.Maybe
import Data.Ratio
import qualified Numeric
import qualified Sound.Sc3.Common.Base as Common.Base
half_pi :: Floating a => a
half_pi :: forall a. Floating a => a
half_pi = a
forall a. Floating a => a
pi a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
2
two_pi :: Floating n => n
two_pi :: forall a. Floating a => a
two_pi = n
2 n -> n -> n
forall a. Num a => a -> a -> a
* n
forall a. Floating a => a
pi
absdif :: Num a => a -> a -> a
absdif :: forall a. Num a => a -> a -> a
absdif a
i a
j = a -> a
forall a. Num a => a -> a
abs (a
j a -> a -> a
forall a. Num a => a -> a -> a
- a
i)
type Sc3_MulAdd t = t -> t -> t -> t
sc3_mul_add :: Num t => Sc3_MulAdd t
sc3_mul_add :: forall t. Num t => Sc3_MulAdd t
sc3_mul_add t
i t
m t
a = t
i t -> t -> t
forall a. Num a => a -> a -> a
* t
m t -> t -> t
forall a. Num a => a -> a -> a
+ t
a
mul_add :: Num t => t -> t -> t -> t
mul_add :: forall t. Num t => Sc3_MulAdd t
mul_add t
m t
a = (t -> t -> t
forall a. Num a => a -> a -> a
+ t
a) (t -> t) -> (t -> t) -> t -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t -> t -> t
forall a. Num a => a -> a -> a
* t
m)
mul_add_hs :: Num t => (t, t) -> t -> t
mul_add_hs :: forall t. Num t => (t, t) -> t -> t
mul_add_hs = (t -> t -> t -> t) -> (t, t) -> t -> t
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry t -> t -> t -> t
forall t. Num t => Sc3_MulAdd t
mul_add
sc3_truncate :: RealFrac a => a -> a
sc3_truncate :: forall a. RealFrac a => a -> a
sc3_truncate = Integer -> a
forall a. Num a => Integer -> a
fromInteger (Integer -> a) -> (a -> Integer) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Integer
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
truncate
sc3_round :: RealFrac a => a -> a
sc3_round :: forall a. RealFrac a => a -> a
sc3_round = Integer -> a
forall a. Num a => Integer -> a
fromInteger (Integer -> a) -> (a -> Integer) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Integer
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
round
sc3_ceiling :: RealFrac a => a -> a
sc3_ceiling :: forall a. RealFrac a => a -> a
sc3_ceiling = Integer -> a
forall a. Num a => Integer -> a
fromInteger (Integer -> a) -> (a -> Integer) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Integer
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
ceiling
sc3_floor :: RealFrac a => a -> a
sc3_floor :: forall a. RealFrac a => a -> a
sc3_floor = Integer -> a
forall a. Num a => Integer -> a
fromInteger (Integer -> a) -> (a -> Integer) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Integer
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor
sc3_round_to :: RealFrac n => n -> n -> n
sc3_round_to :: forall n. RealFrac n => n -> n -> n
sc3_round_to n
a n
b = if n
b n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
0 then n
a else n -> n
forall a. RealFrac a => a -> a
sc3_floor ((n
a n -> n -> n
forall a. Fractional a => a -> a -> a
/ n
b) n -> n -> n
forall a. Num a => a -> a -> a
+ n
0.5) n -> n -> n
forall a. Num a => a -> a -> a
* n
b
sc3_idiv :: RealFrac n => n -> n -> n
sc3_idiv :: forall n. RealFrac n => n -> n -> n
sc3_idiv n
a n
b = Integer -> n
forall a. Num a => Integer -> a
fromInteger (n -> Integer
forall b. Integral b => n -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor n
a Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`div` n -> Integer
forall b. Integral b => n -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor n
b)
sc3_lcm :: t -> t -> t
sc3_lcm :: forall t. t -> t -> t
sc3_lcm = [Char] -> t -> t -> t
forall a. HasCallStack => [Char] -> a
error [Char]
"sc3_lcm: undefined"
sc3_gcd :: t -> t -> t
sc3_gcd :: forall t. t -> t -> t
sc3_gcd = [Char] -> t -> t -> t
forall a. HasCallStack => [Char] -> a
error [Char]
"sc3_gcd: undefined"
sc3_mod :: RealFrac n => n -> n -> n
sc3_mod :: forall n. RealFrac n => n -> n -> n
sc3_mod = n -> n -> n
forall a. Real a => a -> a -> a
Data.Fixed.mod'
fmod_f32 :: Float -> Float -> Float
fmod_f32 :: Float -> Float -> Float
fmod_f32 = Float -> Float -> Float
forall n. RealFrac n => n -> n -> n
sc3_mod
fmod_f64 :: Double -> Double -> Double
fmod_f64 :: Double -> Double -> Double
fmod_f64 = Double -> Double -> Double
forall n. RealFrac n => n -> n -> n
sc3_mod
sc3_clip :: Ord a => a -> a -> a -> a
sc3_clip :: forall a. Ord a => a -> a -> a -> a
sc3_clip a
n a
i a
j = if a
n a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
i then a
i else if a
n a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
j then a
j else a
n
clip_hs :: (Ord a) => (a, a) -> a -> a
clip_hs :: forall a. Ord a => (a, a) -> a -> a
clip_hs (a
i, a
j) a
n = a -> a -> a -> a
forall a. Ord a => a -> a -> a -> a
sc3_clip a
n a
i a
j
sc3_mod_alt :: RealFrac a => a -> a -> a
sc3_mod_alt :: forall n. RealFrac n => n -> n -> n
sc3_mod_alt a
n a
hi =
let lo :: a
lo = a
0.0
in if a
n a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
lo Bool -> Bool -> Bool
&& a
n a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
hi
then a
n
else
if a
hi a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
lo
then a
lo
else a
n a -> a -> a
forall a. Num a => a -> a -> a
- a
hi a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. RealFrac a => a -> a
sc3_floor (a
n a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
hi)
sc3_wrap_ni :: RealFrac a => a -> a -> a -> a
sc3_wrap_ni :: forall a. RealFrac a => a -> a -> a -> a
sc3_wrap_ni a
lo a
hi a
n = a -> a -> a
forall n. RealFrac n => n -> n -> n
sc3_mod (a
n a -> a -> a
forall a. Num a => a -> a -> a
- a
lo) (a
hi a -> a -> a
forall a. Num a => a -> a -> a
- a
lo) a -> a -> a
forall a. Num a => a -> a -> a
+ a
lo
wrap_hs_int :: Integral a => (a, a) -> a -> a
wrap_hs_int :: forall a. Integral a => (a, a) -> a -> a
wrap_hs_int (a
i, a
j) a
n = ((a
n a -> a -> a
forall a. Num a => a -> a -> a
- a
i) a -> a -> a
forall a. Integral a => a -> a -> a
`mod` (a
j a -> a -> a
forall a. Num a => a -> a -> a
- a
i a -> a -> a
forall a. Num a => a -> a -> a
+ a
1)) a -> a -> a
forall a. Num a => a -> a -> a
+ a
i
wrap_hs :: RealFrac n => (n, n) -> n -> n
wrap_hs :: forall n. RealFrac n => (n, n) -> n -> n
wrap_hs (n
i, n
j) n
n =
let r :: n
r = n
j n -> n -> n
forall a. Num a => a -> a -> a
- n
i
n' :: n
n' = if n
n n -> n -> Bool
forall a. Ord a => a -> a -> Bool
>= n
j then n
n n -> n -> n
forall a. Num a => a -> a -> a
- n
r else if n
n n -> n -> Bool
forall a. Ord a => a -> a -> Bool
< n
i then n
n n -> n -> n
forall a. Num a => a -> a -> a
+ n
r else n
n
in if n
n' n -> n -> Bool
forall a. Ord a => a -> a -> Bool
>= n
i Bool -> Bool -> Bool
&& n
n' n -> n -> Bool
forall a. Ord a => a -> a -> Bool
< n
j
then n
n'
else n
n' n -> n -> n
forall a. Num a => a -> a -> a
- n
r n -> n -> n
forall a. Num a => a -> a -> a
* n -> n
forall a. RealFrac a => a -> a
sc3_floor ((n
n' n -> n -> n
forall a. Num a => a -> a -> a
- n
i) n -> n -> n
forall a. Fractional a => a -> a -> a
/ n
r)
sc3_wrap :: RealFrac n => n -> n -> n -> n
sc3_wrap :: forall a. RealFrac a => a -> a -> a -> a
sc3_wrap n
index n
start n
end = (n, n) -> n -> n
forall n. RealFrac n => (n, n) -> n -> n
wrap_hs (n
start, n
end) n
index
generic_wrap :: (Ord a, Num a) => (a, a) -> a -> a
generic_wrap :: forall a. (Ord a, Num a) => (a, a) -> a -> a
generic_wrap (a
l, a
r) a
n =
let d :: a
d = a
r a -> a -> a
forall a. Num a => a -> a -> a
- a
l a -> a -> a
forall a. Num a => a -> a -> a
+ a
1
f :: a -> a
f = (a, a) -> a -> a
forall a. (Ord a, Num a) => (a, a) -> a -> a
generic_wrap (a
l, a
r)
in if a
n a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
l
then a -> a
f (a
n a -> a -> a
forall a. Num a => a -> a -> a
+ a
d)
else if a
n a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
r then a -> a
f (a
n a -> a -> a
forall a. Num a => a -> a -> a
- a
d) else a
n
bin_to_freq :: (Fractional n, Integral i) => n -> i -> i -> n
bin_to_freq :: forall n i. (Fractional n, Integral i) => n -> i -> i -> n
bin_to_freq n
sr i
n i
i = i -> n
forall a b. (Integral a, Num b) => a -> b
fromIntegral i
i n -> n -> n
forall a. Num a => a -> a -> a
* n
sr n -> n -> n
forall a. Fractional a => a -> a -> a
/ i -> n
forall a b. (Integral a, Num b) => a -> b
fromIntegral i
n
midi_to_cps :: Floating a => a -> a
midi_to_cps :: forall a. Floating a => a -> a
midi_to_cps a
i = a
440.0 a -> a -> a
forall a. Num a => a -> a -> a
* (a
2.0 a -> a -> a
forall a. Floating a => a -> a -> a
** ((a
i a -> a -> a
forall a. Num a => a -> a -> a
- a
69.0) a -> a -> a
forall a. Num a => a -> a -> a
* (a
1.0 a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
12.0)))
cps_to_midi :: Floating a => a -> a
cps_to_midi :: forall a. Floating a => a -> a
cps_to_midi a
a = (a -> a -> a
forall a. Floating a => a -> a -> a
logBase a
2 (a
a a -> a -> a
forall a. Num a => a -> a -> a
* (a
1.0 a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
440.0)) a -> a -> a
forall a. Num a => a -> a -> a
* a
12.0) a -> a -> a
forall a. Num a => a -> a -> a
+ a
69.0
cps_to_oct :: Floating a => a -> a
cps_to_oct :: forall a. Floating a => a -> a
cps_to_oct a
a = a -> a -> a
forall a. Floating a => a -> a -> a
logBase a
2 (a
a a -> a -> a
forall a. Num a => a -> a -> a
* (a
1.0 a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
440.0)) a -> a -> a
forall a. Num a => a -> a -> a
+ a
4.75
oct_to_cps :: Floating a => a -> a
oct_to_cps :: forall a. Floating a => a -> a
oct_to_cps a
a = a
440.0 a -> a -> a
forall a. Num a => a -> a -> a
* (a
2.0 a -> a -> a
forall a. Floating a => a -> a -> a
** (a
a a -> a -> a
forall a. Num a => a -> a -> a
- a
4.75))
degree_to_key :: RealFrac a => [a] -> a -> a -> a
degree_to_key :: forall a. RealFrac a => [a] -> a -> a -> a
degree_to_key [a]
s a
n a
d =
let l :: Int
l = [a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
s
d' :: Int
d' = a -> Int
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
round a
d
a :: a
a = (a
d a -> a -> a
forall a. Num a => a -> a -> a
- Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
d') a -> a -> a
forall a. Num a => a -> a -> a
* a
10.0 a -> a -> a
forall a. Num a => a -> a -> a
* (a
n a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
12.0)
in (a
n a -> a -> a
forall a. Num a => a -> a -> a
* Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
d' Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
l)) a -> a -> a
forall a. Num a => a -> a -> a
+ [Char] -> [a] -> Int -> a
forall t. [Char] -> [t] -> Int -> t
Common.Base.at_with_error_message [Char]
"degree_to_key" [a]
s (Int
d' Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
l) a -> a -> a
forall a. Num a => a -> a -> a
+ a
a
pianokey_to_midi :: Num n => n -> n
pianokey_to_midi :: forall a. Num a => a -> a
pianokey_to_midi = n -> n -> n
forall a. Num a => a -> a -> a
(+) n
20
pianokey_to_cps :: Floating n => n -> n
pianokey_to_cps :: forall a. Floating a => a -> a
pianokey_to_cps = n -> n
forall a. Floating a => a -> a
midi_to_cps (n -> n) -> (n -> n) -> n -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. n -> n
forall a. Num a => a -> a
pianokey_to_midi
amp_to_db :: Floating a => a -> a
amp_to_db :: forall a. Floating a => a -> a
amp_to_db = (a -> a -> a
forall a. Num a => a -> a -> a
* a
20) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a -> a
forall a. Floating a => a -> a -> a
logBase a
10
db_to_amp :: Floating a => a -> a
db_to_amp :: forall a. Floating a => a -> a
db_to_amp = (a
10 a -> a -> a
forall a. Floating a => a -> a -> a
**) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a -> a
forall a. Num a => a -> a -> a
* a
0.05)
midi_to_ratio :: Floating a => a -> a
midi_to_ratio :: forall a. Floating a => a -> a
midi_to_ratio a
a = a
2.0 a -> a -> a
forall a. Floating a => a -> a -> a
** (a
a a -> a -> a
forall a. Num a => a -> a -> a
* (a
1.0 a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
12.0))
ratio_to_midi :: Floating a => a -> a
ratio_to_midi :: forall a. Floating a => a -> a
ratio_to_midi a
a = a
12.0 a -> a -> a
forall a. Num a => a -> a -> a
* a -> a -> a
forall a. Floating a => a -> a -> a
logBase a
2 a
a
cps_to_incr :: Fractional a => a -> a -> a -> a
cps_to_incr :: forall a. Fractional a => a -> a -> a -> a
cps_to_incr a
sr a
r a
cps = (a
r a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
sr) a -> a -> a
forall a. Num a => a -> a -> a
* a
cps
incr_to_cps :: Fractional a => a -> a -> a -> a
incr_to_cps :: forall a. Fractional a => a -> a -> a -> a
incr_to_cps a
sr a
r a
ic = a
ic a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
r a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
sr)
pan2_f :: Fractional t => (t -> t) -> t -> t -> (t, t)
pan2_f :: forall t. Fractional t => (t -> t) -> t -> t -> (t, t)
pan2_f t -> t
f t
p t
q =
let q' :: t
q' = (t
q t -> t -> t
forall a. Fractional a => a -> a -> a
/ t
2) t -> t -> t
forall a. Num a => a -> a -> a
+ t
0.5
in (t
p t -> t -> t
forall a. Num a => a -> a -> a
* t -> t
f (t
1 t -> t -> t
forall a. Num a => a -> a -> a
- t
q'), t
p t -> t -> t
forall a. Num a => a -> a -> a
* t -> t
f t
q')
lin_pan2 :: Fractional t => t -> t -> (t, t)
lin_pan2 :: forall t. Fractional t => t -> t -> (t, t)
lin_pan2 = (t -> t) -> t -> t -> (t, t)
forall t. Fractional t => (t -> t) -> t -> t -> (t, t)
pan2_f t -> t
forall a. a -> a
id
eq_pan2 :: Floating t => t -> t -> (t, t)
eq_pan2 :: forall t. Floating t => t -> t -> (t, t)
eq_pan2 = (t -> t) -> t -> t -> (t, t)
forall t. Fractional t => (t -> t) -> t -> t -> (t, t)
pan2_f t -> t
forall a. Floating a => a -> a
sqrt
sc3_properFraction :: RealFrac t => t -> (t, t)
sc3_properFraction :: forall t. RealFrac t => t -> (t, t)
sc3_properFraction t
a =
let (Integer
p, t
q) = t -> (Integer, t)
forall b. Integral b => t -> (b, t)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction t
a
in (Integer -> t
forall a. Num a => Integer -> a
fromInteger Integer
p, t
q)
sc3_dif_sqr :: Num a => a -> a -> a
sc3_dif_sqr :: forall a. Num a => a -> a -> a
sc3_dif_sqr a
a a
b = (a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
a) a -> a -> a
forall a. Num a => a -> a -> a
- (a
b a -> a -> a
forall a. Num a => a -> a -> a
* a
b)
sc3_hypot :: Floating a => a -> a -> a
sc3_hypot :: forall a. Floating a => a -> a -> a
sc3_hypot a
x a
y = a -> a
forall a. Floating a => a -> a
sqrt (a
x a -> a -> a
forall a. Num a => a -> a -> a
* a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
y a -> a -> a
forall a. Num a => a -> a -> a
* a
y)
sc3_hypotx :: (Ord a, Floating a) => a -> a -> a
sc3_hypotx :: forall a. (Ord a, Floating a) => a -> a -> a
sc3_hypotx a
x a
y = a -> a
forall a. Num a => a -> a
abs a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a -> a
forall a. Num a => a -> a
abs a
y a -> a -> a
forall a. Num a => a -> a -> a
- ((a -> a
forall a. Floating a => a -> a
sqrt a
2 a -> a -> a
forall a. Num a => a -> a -> a
- a
1) a -> a -> a
forall a. Num a => a -> a -> a
* a -> a -> a
forall a. Ord a => a -> a -> a
min (a -> a
forall a. Num a => a -> a
abs a
x) (a -> a
forall a. Num a => a -> a
abs a
y))
foldToRange :: (Ord a, Num a) => a -> a -> a -> a
foldToRange :: forall a. (Ord a, Num a) => a -> a -> a -> a
foldToRange a
i a
j =
let f :: a -> a
f a
n =
if a
n a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
j
then a -> a
f (a
j a -> a -> a
forall a. Num a => a -> a -> a
- (a
n a -> a -> a
forall a. Num a => a -> a -> a
- a
j))
else
if a
n a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
i
then a -> a
f (a
i a -> a -> a
forall a. Num a => a -> a -> a
- (a
n a -> a -> a
forall a. Num a => a -> a -> a
- a
i))
else a
n
in a -> a
f
sc3_fold :: (Ord a, Num a) => a -> a -> a -> a
sc3_fold :: forall a. (Ord a, Num a) => a -> a -> a -> a
sc3_fold a
n a
i a
j = a -> a -> a -> a
forall a. (Ord a, Num a) => a -> a -> a -> a
foldToRange a
i a
j a
n
sc3_distort :: Fractional n => n -> n
sc3_distort :: forall n. Fractional n => n -> n
sc3_distort n
x = n
x n -> n -> n
forall a. Fractional a => a -> a -> a
/ (n
1 n -> n -> n
forall a. Num a => a -> a -> a
+ n -> n
forall a. Num a => a -> a
abs n
x)
sc3_softclip :: (Ord n, Fractional n) => n -> n
sc3_softclip :: forall n. (Ord n, Fractional n) => n -> n
sc3_softclip n
x = let x' :: n
x' = n -> n
forall a. Num a => a -> a
abs n
x in if n
x' n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<= n
0.5 then n
x else (n
x' n -> n -> n
forall a. Num a => a -> a -> a
- n
0.25) n -> n -> n
forall a. Fractional a => a -> a -> a
/ n
x
sc3_true :: Num n => n
sc3_true :: forall n. Num n => n
sc3_true = n
1
sc3_false :: Num n => n
sc3_false :: forall n. Num n => n
sc3_false = n
0
sc3_not :: (Ord n, Num n) => n -> n
sc3_not :: forall n. (Ord n, Num n) => n -> n
sc3_not = Bool -> n
forall n. Num n => Bool -> n
sc3_bool (Bool -> n) -> (n -> Bool) -> n -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<= n
0)
sc3_bool :: Num n => Bool -> n
sc3_bool :: forall n. Num n => Bool -> n
sc3_bool Bool
b = if Bool
b then n
forall n. Num n => n
sc3_true else n
forall n. Num n => n
sc3_false
sc3_comparison :: Num n => (n -> n -> Bool) -> n -> n -> n
sc3_comparison :: forall n. Num n => (n -> n -> Bool) -> n -> n -> n
sc3_comparison n -> n -> Bool
f n
p n
q = Bool -> n
forall n. Num n => Bool -> n
sc3_bool (n -> n -> Bool
f n
p n
q)
sc3_eq :: (Num n, Eq n) => n -> n -> n
sc3_eq :: forall n. (Num n, Eq n) => n -> n -> n
sc3_eq = (n -> n -> Bool) -> n -> n -> n
forall n. Num n => (n -> n -> Bool) -> n -> n -> n
sc3_comparison n -> n -> Bool
forall a. Eq a => a -> a -> Bool
(==)
sc3_neq :: (Num n, Eq n) => n -> n -> n
sc3_neq :: forall n. (Num n, Eq n) => n -> n -> n
sc3_neq = (n -> n -> Bool) -> n -> n -> n
forall n. Num n => (n -> n -> Bool) -> n -> n -> n
sc3_comparison n -> n -> Bool
forall a. Eq a => a -> a -> Bool
(/=)
sc3_lt :: (Num n, Ord n) => n -> n -> n
sc3_lt :: forall n. (Num n, Ord n) => n -> n -> n
sc3_lt = (n -> n -> Bool) -> n -> n -> n
forall n. Num n => (n -> n -> Bool) -> n -> n -> n
sc3_comparison n -> n -> Bool
forall a. Ord a => a -> a -> Bool
(<)
sc3_lte :: (Num n, Ord n) => n -> n -> n
sc3_lte :: forall n. (Num n, Ord n) => n -> n -> n
sc3_lte = (n -> n -> Bool) -> n -> n -> n
forall n. Num n => (n -> n -> Bool) -> n -> n -> n
sc3_comparison n -> n -> Bool
forall a. Ord a => a -> a -> Bool
(<=)
sc3_gt :: (Num n, Ord n) => n -> n -> n
sc3_gt :: forall n. (Num n, Ord n) => n -> n -> n
sc3_gt = (n -> n -> Bool) -> n -> n -> n
forall n. Num n => (n -> n -> Bool) -> n -> n -> n
sc3_comparison n -> n -> Bool
forall a. Ord a => a -> a -> Bool
(>)
sc3_gte :: (Num n, Ord n) => n -> n -> n
sc3_gte :: forall n. (Num n, Ord n) => n -> n -> n
sc3_gte = (n -> n -> Bool) -> n -> n -> n
forall n. Num n => (n -> n -> Bool) -> n -> n -> n
sc3_comparison n -> n -> Bool
forall a. Ord a => a -> a -> Bool
(>=)
data Clip_Rule = Clip_None | Clip_Left | Clip_Right | Clip_Both
deriving (Int -> Clip_Rule
Clip_Rule -> Int
Clip_Rule -> [Clip_Rule]
Clip_Rule -> Clip_Rule
Clip_Rule -> Clip_Rule -> [Clip_Rule]
Clip_Rule -> Clip_Rule -> Clip_Rule -> [Clip_Rule]
(Clip_Rule -> Clip_Rule)
-> (Clip_Rule -> Clip_Rule)
-> (Int -> Clip_Rule)
-> (Clip_Rule -> Int)
-> (Clip_Rule -> [Clip_Rule])
-> (Clip_Rule -> Clip_Rule -> [Clip_Rule])
-> (Clip_Rule -> Clip_Rule -> [Clip_Rule])
-> (Clip_Rule -> Clip_Rule -> Clip_Rule -> [Clip_Rule])
-> Enum Clip_Rule
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Clip_Rule -> Clip_Rule
succ :: Clip_Rule -> Clip_Rule
$cpred :: Clip_Rule -> Clip_Rule
pred :: Clip_Rule -> Clip_Rule
$ctoEnum :: Int -> Clip_Rule
toEnum :: Int -> Clip_Rule
$cfromEnum :: Clip_Rule -> Int
fromEnum :: Clip_Rule -> Int
$cenumFrom :: Clip_Rule -> [Clip_Rule]
enumFrom :: Clip_Rule -> [Clip_Rule]
$cenumFromThen :: Clip_Rule -> Clip_Rule -> [Clip_Rule]
enumFromThen :: Clip_Rule -> Clip_Rule -> [Clip_Rule]
$cenumFromTo :: Clip_Rule -> Clip_Rule -> [Clip_Rule]
enumFromTo :: Clip_Rule -> Clip_Rule -> [Clip_Rule]
$cenumFromThenTo :: Clip_Rule -> Clip_Rule -> Clip_Rule -> [Clip_Rule]
enumFromThenTo :: Clip_Rule -> Clip_Rule -> Clip_Rule -> [Clip_Rule]
Enum, Clip_Rule
Clip_Rule -> Clip_Rule -> Bounded Clip_Rule
forall a. a -> a -> Bounded a
$cminBound :: Clip_Rule
minBound :: Clip_Rule
$cmaxBound :: Clip_Rule
maxBound :: Clip_Rule
Bounded)
apply_clip_rule :: Ord n => Clip_Rule -> n -> n -> n -> n -> n -> Maybe n
apply_clip_rule :: forall n. Ord n => Clip_Rule -> n -> n -> n -> n -> n -> Maybe n
apply_clip_rule Clip_Rule
clip_rule n
sl n
sr n
dl n
dr n
x =
case Clip_Rule
clip_rule of
Clip_Rule
Clip_None -> Maybe n
forall a. Maybe a
Nothing
Clip_Rule
Clip_Left -> if n
x n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<= n
sl then n -> Maybe n
forall a. a -> Maybe a
Just n
dl else Maybe n
forall a. Maybe a
Nothing
Clip_Rule
Clip_Right -> if n
x n -> n -> Bool
forall a. Ord a => a -> a -> Bool
>= n
sr then n -> Maybe n
forall a. a -> Maybe a
Just n
dr else Maybe n
forall a. Maybe a
Nothing
Clip_Rule
Clip_Both -> if n
x n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<= n
sl then n -> Maybe n
forall a. a -> Maybe a
Just n
dl else if n
x n -> n -> Bool
forall a. Ord a => a -> a -> Bool
>= n
sr then n -> Maybe n
forall a. a -> Maybe a
Just n
dr else Maybe n
forall a. Maybe a
Nothing
urange_ma :: Fractional a => Sc3_MulAdd a -> a -> a -> a -> a
urange_ma :: forall a. Fractional a => Sc3_MulAdd a -> Sc3_MulAdd a
urange_ma Sc3_MulAdd a
mul_add_f a
l a
r a
i = Sc3_MulAdd a
mul_add_f a
i (a
r a -> a -> a
forall a. Num a => a -> a -> a
- a
l) a
l
urange :: Fractional a => a -> a -> a -> a
urange :: forall a. Fractional a => a -> a -> a -> a
urange = Sc3_MulAdd a -> Sc3_MulAdd a
forall a. Fractional a => Sc3_MulAdd a -> Sc3_MulAdd a
urange_ma Sc3_MulAdd a
forall t. Num t => Sc3_MulAdd t
sc3_mul_add
range_muladd :: Fractional t => t -> t -> (t, t)
range_muladd :: forall t. Fractional t => t -> t -> (t, t)
range_muladd = t -> t -> t -> t -> (t, t)
forall t. Fractional t => t -> t -> t -> t -> (t, t)
linlin_muladd (-t
1) t
1
range_ma :: Fractional a => Sc3_MulAdd a -> a -> a -> a -> a
range_ma :: forall a. Fractional a => Sc3_MulAdd a -> Sc3_MulAdd a
range_ma Sc3_MulAdd a
mul_add_f a
l a
r a
i =
let (a
m, a
a) = a -> a -> (a, a)
forall t. Fractional t => t -> t -> (t, t)
range_muladd a
l a
r
in Sc3_MulAdd a
mul_add_f a
i a
m a
a
range :: Fractional a => a -> a -> a -> a
range :: forall a. Fractional a => a -> a -> a -> a
range = Sc3_MulAdd a -> Sc3_MulAdd a
forall a. Fractional a => Sc3_MulAdd a -> Sc3_MulAdd a
range_ma Sc3_MulAdd a
forall t. Num t => Sc3_MulAdd t
sc3_mul_add
range_hs :: Fractional a => (a, a) -> a -> a
range_hs :: forall a. Fractional a => (a, a) -> a -> a
range_hs = (a -> a -> a -> a) -> (a, a) -> a -> a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> a -> a -> a
forall a. Fractional a => a -> a -> a -> a
range
in_range :: Fractional a => a -> (a, a) -> a
in_range :: forall a. Fractional a => a -> (a, a) -> a
in_range = ((a, a) -> a -> a) -> a -> (a, a) -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a, a) -> a -> a
forall a. Fractional a => (a, a) -> a -> a
range_hs
linlin_muladd :: Fractional t => t -> t -> t -> t -> (t, t)
linlin_muladd :: forall t. Fractional t => t -> t -> t -> t -> (t, t)
linlin_muladd t
sl t
sr t
dl t
dr =
let m :: t
m = (t
dr t -> t -> t
forall a. Num a => a -> a -> a
- t
dl) t -> t -> t
forall a. Fractional a => a -> a -> a
/ (t
sr t -> t -> t
forall a. Num a => a -> a -> a
- t
sl)
a :: t
a = t
dl t -> t -> t
forall a. Num a => a -> a -> a
- (t
m t -> t -> t
forall a. Num a => a -> a -> a
* t
sl)
in (t
m, t
a)
linlin_ma :: Fractional a => Sc3_MulAdd a -> a -> a -> a -> a -> a -> a
linlin_ma :: forall a. Fractional a => Sc3_MulAdd a -> a -> a -> Sc3_MulAdd a
linlin_ma Sc3_MulAdd a
mul_add_f a
i a
sl a
sr a
dl a
dr =
let (a
m, a
a) = a -> a -> a -> a -> (a, a)
forall t. Fractional t => t -> t -> t -> t -> (t, t)
linlin_muladd a
sl a
sr a
dl a
dr
in Sc3_MulAdd a
mul_add_f a
i a
m a
a
linlin_hs :: Fractional a => (a, a) -> (a, a) -> a -> a
linlin_hs :: forall a. Fractional a => (a, a) -> (a, a) -> a -> a
linlin_hs (a
sl, a
sr) (a
dl, a
dr) = let (a
m, a
a) = a -> a -> a -> a -> (a, a)
forall t. Fractional t => t -> t -> t -> t -> (t, t)
linlin_muladd a
sl a
sr a
dl a
dr in (a -> a -> a
forall a. Num a => a -> a -> a
+ a
a) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a -> a
forall a. Num a => a -> a -> a
* a
m)
sc3_linlin :: Fractional a => a -> a -> a -> a -> a -> a
sc3_linlin :: forall a. Fractional a => a -> a -> a -> a -> a -> a
sc3_linlin a
i a
sl a
sr a
dl a
dr = (a, a) -> (a, a) -> a -> a
forall a. Fractional a => (a, a) -> (a, a) -> a -> a
linlin_hs (a
sl, a
sr) (a
dl, a
dr) a
i
linlin_enum_plain :: (Enum t, Enum u) => t -> u -> t -> u
linlin_enum_plain :: forall t u. (Enum t, Enum u) => t -> u -> t -> u
linlin_enum_plain t
src u
dst t
n = Int -> u
forall a. Enum a => Int -> a
toEnum (u -> Int
forall a. Enum a => a -> Int
fromEnum u
dst Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (t -> Int
forall a. Enum a => a -> Int
fromEnum t
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- t -> Int
forall a. Enum a => a -> Int
fromEnum t
src))
linlin_enum :: (Enum t, Enum u) => (t, t) -> (u, u) -> t -> Maybe u
linlin_enum :: forall t u. (Enum t, Enum u) => (t, t) -> (u, u) -> t -> Maybe u
linlin_enum (t
l, t
r) (u
l', u
r') t
n =
if t -> Int
forall a. Enum a => a -> Int
fromEnum t
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= t -> Int
forall a. Enum a => a -> Int
fromEnum t
l Bool -> Bool -> Bool
&& t -> Int
forall a. Enum a => a -> Int
fromEnum t
r Int -> Int -> Int
forall a. Num a => a -> a -> a
- t -> Int
forall a. Enum a => a -> Int
fromEnum t
l Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== u -> Int
forall a. Enum a => a -> Int
fromEnum u
r' Int -> Int -> Int
forall a. Num a => a -> a -> a
- u -> Int
forall a. Enum a => a -> Int
fromEnum u
l'
then u -> Maybe u
forall a. a -> Maybe a
Just (t -> u -> t -> u
forall t u. (Enum t, Enum u) => t -> u -> t -> u
linlin_enum_plain t
l u
l' t
n)
else Maybe u
forall a. Maybe a
Nothing
linlin_enum_err :: (Enum t, Enum u) => (t, t) -> (u, u) -> t -> u
linlin_enum_err :: forall t u. (Enum t, Enum u) => (t, t) -> (u, u) -> t -> u
linlin_enum_err (t, t)
src (u, u)
dst = u -> Maybe u -> u
forall a. a -> Maybe a -> a
fromMaybe ([Char] -> u
forall a. HasCallStack => [Char] -> a
error [Char]
"linlin_enum") (Maybe u -> u) -> (t -> Maybe u) -> t -> u
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t, t) -> (u, u) -> t -> Maybe u
forall t u. (Enum t, Enum u) => (t, t) -> (u, u) -> t -> Maybe u
linlin_enum (t, t)
src (u, u)
dst
linlin_eq :: (Eq a, Num a) => (a, a) -> (a, a) -> a -> Maybe a
linlin_eq :: forall a. (Eq a, Num a) => (a, a) -> (a, a) -> a -> Maybe a
linlin_eq (a
l, a
r) (a
l', a
r') a
n =
let d :: a
d = a
r a -> a -> a
forall a. Num a => a -> a -> a
- a
l
d' :: a
d' = a
r' a -> a -> a
forall a. Num a => a -> a -> a
- a
l'
in if a
d a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
d' then a -> Maybe a
forall a. a -> Maybe a
Just (a
l' a -> a -> a
forall a. Num a => a -> a -> a
+ (a
n a -> a -> a
forall a. Num a => a -> a -> a
- a
l)) else Maybe a
forall a. Maybe a
Nothing
linlin_eq_err :: (Eq a, Num a) => (a, a) -> (a, a) -> a -> a
linlin_eq_err :: forall a. (Eq a, Num a) => (a, a) -> (a, a) -> a -> a
linlin_eq_err (a, a)
src (a, a)
dst = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe ([Char] -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"linlin_eq") (Maybe a -> a) -> (a -> Maybe a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, a) -> (a, a) -> a -> Maybe a
forall a. (Eq a, Num a) => (a, a) -> (a, a) -> a -> Maybe a
linlin_eq (a, a)
src (a, a)
dst
linexp_hs :: Floating a => (a, a) -> (a, a) -> a -> a
linexp_hs :: forall a. Floating a => (a, a) -> (a, a) -> a -> a
linexp_hs (a
in_l, a
in_r) (a
out_l, a
out_r) a
x =
let rt :: a
rt = a
out_r a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
out_l
rn :: a
rn = a
1.0 a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
in_r a -> a -> a
forall a. Num a => a -> a -> a
- a
in_l)
rr :: a
rr = a
rn a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Num a => a -> a
negate a
in_l
in a
out_l a -> a -> a
forall a. Num a => a -> a -> a
* (a
rt a -> a -> a
forall a. Floating a => a -> a -> a
** (a
x a -> a -> a
forall a. Num a => a -> a -> a
* a
rn a -> a -> a
forall a. Num a => a -> a -> a
+ a
rr))
lin_exp :: Floating a => a -> a -> a -> a -> a -> a
lin_exp :: forall a. Floating a => a -> a -> a -> a -> a -> a
lin_exp a
x a
in_l a
in_r a
out_l a
out_r = (a, a) -> (a, a) -> a -> a
forall a. Floating a => (a, a) -> (a, a) -> a -> a
linexp_hs (a
in_l, a
in_r) (a
out_l, a
out_r) a
x
sc3_linexp :: (Ord a, Floating a) => a -> a -> a -> a -> a -> a
sc3_linexp :: forall a. (Ord a, Floating a) => a -> a -> a -> a -> a -> a
sc3_linexp a
src_l a
src_r a
dst_l a
dst_r a
x =
case Clip_Rule -> a -> a -> a -> a -> a -> Maybe a
forall n. Ord n => Clip_Rule -> n -> n -> n -> n -> n -> Maybe n
apply_clip_rule Clip_Rule
Clip_Both a
src_l a
src_r a
dst_l a
dst_r a
x of
Just a
r -> a
r
Maybe a
Nothing -> ((a
dst_r a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
dst_l) a -> a -> a
forall a. Floating a => a -> a -> a
** ((a
x a -> a -> a
forall a. Num a => a -> a -> a
- a
src_l) a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
src_r a -> a -> a
forall a. Num a => a -> a -> a
- a
src_l))) a -> a -> a
forall a. Num a => a -> a -> a
* a
dst_l
sc3_explin :: (Ord a, Floating a) => a -> a -> a -> a -> a -> a
sc3_explin :: forall a. (Ord a, Floating a) => a -> a -> a -> a -> a -> a
sc3_explin a
src_l a
src_r a
dst_l a
dst_r a
x =
a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe
(a -> a -> a
forall a. Floating a => a -> a -> a
logBase (a
src_r a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
src_l) (a
x a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
src_l) a -> a -> a
forall a. Num a => a -> a -> a
* (a
dst_r a -> a -> a
forall a. Num a => a -> a -> a
- a
dst_l) a -> a -> a
forall a. Num a => a -> a -> a
+ a
dst_l)
(Clip_Rule -> a -> a -> a -> a -> a -> Maybe a
forall n. Ord n => Clip_Rule -> n -> n -> n -> n -> n -> Maybe n
apply_clip_rule Clip_Rule
Clip_Both a
src_l a
src_r a
dst_l a
dst_r a
x)
sc3_expexp :: (Ord a, Floating a) => a -> a -> a -> a -> a -> a
sc3_expexp :: forall a. (Ord a, Floating a) => a -> a -> a -> a -> a -> a
sc3_expexp a
src_l a
src_r a
dst_l a
dst_r a
x =
a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe
((a
dst_r a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
dst_l) a -> a -> a
forall a. Floating a => a -> a -> a
** a -> a -> a
forall a. Floating a => a -> a -> a
logBase (a
src_r a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
src_l) (a
x a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
src_l) a -> a -> a
forall a. Num a => a -> a -> a
* a
dst_l)
(Clip_Rule -> a -> a -> a -> a -> a -> Maybe a
forall n. Ord n => Clip_Rule -> n -> n -> n -> n -> n -> Maybe n
apply_clip_rule Clip_Rule
Clip_Both a
src_l a
src_r a
dst_l a
dst_r a
x)
sc3_lincurve :: (Ord a, Floating a) => a -> a -> a -> a -> a -> a -> a
sc3_lincurve :: forall a. (Ord a, Floating a) => a -> a -> a -> a -> a -> a -> a
sc3_lincurve a
curve a
src_l a
src_r a
dst_l a
dst_r a
x =
case Clip_Rule -> a -> a -> a -> a -> a -> Maybe a
forall n. Ord n => Clip_Rule -> n -> n -> n -> n -> n -> Maybe n
apply_clip_rule Clip_Rule
Clip_Both a
src_l a
src_r a
dst_l a
dst_r a
x of
Just a
r -> a
r
Maybe a
Nothing ->
if a -> a
forall a. Num a => a -> a
abs a
curve a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0.001
then (a, a) -> (a, a) -> a -> a
forall a. Fractional a => (a, a) -> (a, a) -> a -> a
linlin_hs (a
src_l, a
src_r) (a
dst_l, a
dst_r) a
x
else
let grow :: a
grow = a -> a
forall a. Floating a => a -> a
exp a
curve
a :: a
a = (a
dst_r a -> a -> a
forall a. Num a => a -> a -> a
- a
dst_l) a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
1.0 a -> a -> a
forall a. Num a => a -> a -> a
- a
grow)
b :: a
b = a
dst_l a -> a -> a
forall a. Num a => a -> a -> a
+ a
a
scaled :: a
scaled = (a
x a -> a -> a
forall a. Num a => a -> a -> a
- a
src_l) a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
src_r a -> a -> a
forall a. Num a => a -> a -> a
- a
src_l)
in a
b a -> a -> a
forall a. Num a => a -> a -> a
- (a
a a -> a -> a
forall a. Num a => a -> a -> a
* (a
grow a -> a -> a
forall a. Floating a => a -> a -> a
** a
scaled))
sc3_curvelin :: (Ord a, Floating a) => a -> a -> a -> a -> a -> a -> a
sc3_curvelin :: forall a. (Ord a, Floating a) => a -> a -> a -> a -> a -> a -> a
sc3_curvelin a
curve a
src_l a
src_r a
dst_l a
dst_r a
x =
case Clip_Rule -> a -> a -> a -> a -> a -> Maybe a
forall n. Ord n => Clip_Rule -> n -> n -> n -> n -> n -> Maybe n
apply_clip_rule Clip_Rule
Clip_Both a
src_l a
src_r a
dst_l a
dst_r a
x of
Just a
r -> a
r
Maybe a
Nothing ->
if a -> a
forall a. Num a => a -> a
abs a
curve a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0.001
then (a, a) -> (a, a) -> a -> a
forall a. Fractional a => (a, a) -> (a, a) -> a -> a
linlin_hs (a
src_l, a
src_r) (a
dst_l, a
dst_r) a
x
else
let grow :: a
grow = a -> a
forall a. Floating a => a -> a
exp a
curve
a :: a
a = (a
src_r a -> a -> a
forall a. Num a => a -> a -> a
- a
src_l) a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
1.0 a -> a -> a
forall a. Num a => a -> a -> a
- a
grow)
b :: a
b = a
src_l a -> a -> a
forall a. Num a => a -> a -> a
+ a
a
in a -> a
forall a. Floating a => a -> a
log ((a
b a -> a -> a
forall a. Num a => a -> a -> a
- a
x) a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
a) a -> a -> a
forall a. Num a => a -> a -> a
* (a
dst_r a -> a -> a
forall a. Num a => a -> a -> a
- a
dst_l) a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
curve a -> a -> a
forall a. Num a => a -> a -> a
+ a
dst_l
double_pp_rm0 :: String -> String
double_pp_rm0 :: [Char] -> [Char]
double_pp_rm0 =
let rev_f :: ([a] -> [a]) -> [a] -> [a]
rev_f [a] -> [a]
f = [a] -> [a]
forall a. [a] -> [a]
reverse ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
f ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. [a] -> [a]
reverse
remv :: [Char] -> [Char]
remv [Char]
l = case [Char]
l of
Char
'0' : Char
'.' : [Char]
_ -> [Char]
l
Char
'0' : [Char]
l' -> [Char] -> [Char]
remv [Char]
l'
[Char]
_ -> [Char]
l
in ([Char] -> [Char]) -> [Char] -> [Char]
forall {a} {a}. ([a] -> [a]) -> [a] -> [a]
rev_f [Char] -> [Char]
remv
double_pp :: Int -> Double -> String
double_pp :: Int -> Double -> [Char]
double_pp Int
k Double
n = [Char] -> [Char]
double_pp_rm0 (Maybe Int -> Double -> [Char] -> [Char]
forall a. RealFloat a => Maybe Int -> a -> [Char] -> [Char]
Numeric.showFFloat (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
k) Double
n [Char]
"")
real_pp :: Int -> Double -> String
real_pp :: Int -> Double -> [Char]
real_pp Int
k Double
n =
let r :: Rational
r = Double -> Rational
forall a. Real a => a -> Rational
toRational Double
n
in if Rational -> Integer
forall a. Ratio a -> a
denominator Rational
r Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
1 then Integer -> [Char]
forall a. Show a => a -> [Char]
show (Rational -> Integer
forall a. Ratio a -> a
numerator Rational
r) else Int -> Double -> [Char]
double_pp Int
k Double
n
parse_double :: String -> Maybe Double
parse_double :: [Char] -> Maybe Double
parse_double = [Char] -> Maybe Double
forall a. Read a => [Char] -> Maybe a
Common.Base.reads_exact
sum_opt_f :: Num t => (t -> t -> t -> t) -> (t -> t -> t -> t -> t) -> [t] -> t
sum_opt_f :: forall t.
Num t =>
(t -> t -> t -> t) -> (t -> t -> t -> t -> t) -> [t] -> t
sum_opt_f t -> t -> t -> t
f3 t -> t -> t -> t -> t
f4 =
let recur :: [t] -> t
recur [t]
l =
case [t]
l of
t
p : t
q : t
r : t
s : [t]
l' -> [t] -> t
recur (t -> t -> t -> t -> t
f4 t
p t
q t
r t
s t -> [t] -> [t]
forall a. a -> [a] -> [a]
: [t]
l')
t
p : t
q : t
r : [t]
l' -> [t] -> t
recur (t -> t -> t -> t
f3 t
p t
q t
r t -> [t] -> [t]
forall a. a -> [a] -> [a]
: [t]
l')
[t]
_ -> [t] -> t
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [t]
l
in [t] -> t
recur
sin_taylor_approximation :: Floating a => a -> a
sin_taylor_approximation :: forall a. Floating a => a -> a
sin_taylor_approximation a
x = a
x a -> a -> a
forall a. Num a => a -> a -> a
- (a
x a -> a -> a
forall a. Floating a => a -> a -> a
** a
3) a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
3 a -> a -> a
forall a. Num a => a -> a -> a
* a
2) a -> a -> a
forall a. Num a => a -> a -> a
+ (a
x a -> a -> a
forall a. Floating a => a -> a -> a
** a
5) a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
5 a -> a -> a
forall a. Num a => a -> a -> a
* a
4 a -> a -> a
forall a. Num a => a -> a -> a
* a
3 a -> a -> a
forall a. Num a => a -> a -> a
* a
2) a -> a -> a
forall a. Num a => a -> a -> a
- (a
x a -> a -> a
forall a. Floating a => a -> a -> a
** a
7) a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
7 a -> a -> a
forall a. Num a => a -> a -> a
* a
6 a -> a -> a
forall a. Num a => a -> a -> a
* a
5 a -> a -> a
forall a. Num a => a -> a -> a
* a
4 a -> a -> a
forall a. Num a => a -> a -> a
* a
3 a -> a -> a
forall a. Num a => a -> a -> a
* a
2) a -> a -> a
forall a. Num a => a -> a -> a
+ (a
x a -> a -> a
forall a. Floating a => a -> a -> a
** a
9) a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
9 a -> a -> a
forall a. Num a => a -> a -> a
* a
8 a -> a -> a
forall a. Num a => a -> a -> a
* a
7 a -> a -> a
forall a. Num a => a -> a -> a
* a
6 a -> a -> a
forall a. Num a => a -> a -> a
* a
5 a -> a -> a
forall a. Num a => a -> a -> a
* a
4 a -> a -> a
forall a. Num a => a -> a -> a
* a
3 a -> a -> a
forall a. Num a => a -> a -> a
* a
2)
sin_bhaskara_approximation :: Floating a => a -> a
sin_bhaskara_approximation :: forall a. Floating a => a -> a
sin_bhaskara_approximation a
x = (a
16 a -> a -> a
forall a. Num a => a -> a -> a
* a
x a -> a -> a
forall a. Num a => a -> a -> a
* (a
forall a. Floating a => a
pi a -> a -> a
forall a. Num a => a -> a -> a
- a
x)) a -> a -> a
forall a. Fractional a => a -> a -> a
/ ((a
5 a -> a -> a
forall a. Num a => a -> a -> a
* a
forall a. Floating a => a
pi a -> a -> a
forall a. Num a => a -> a -> a
* a
forall a. Floating a => a
pi) a -> a -> a
forall a. Num a => a -> a -> a
- (a
4 a -> a -> a
forall a. Num a => a -> a -> a
* a
x a -> a -> a
forall a. Num a => a -> a -> a
* (a
forall a. Floating a => a
pi a -> a -> a
forall a. Num a => a -> a -> a
- a
x)))
sin_green_approximation :: Floating a => a -> a
sin_green_approximation :: forall a. Floating a => a -> a
sin_green_approximation a
x = a
x a -> a -> a
forall a. Num a => a -> a -> a
- (a
0.166666546 a -> a -> a
forall a. Num a => a -> a -> a
* (a
x a -> a -> a
forall a. Floating a => a -> a -> a
** a
3)) a -> a -> a
forall a. Num a => a -> a -> a
+ (a
0.00833216076 a -> a -> a
forall a. Num a => a -> a -> a
* (a
x a -> a -> a
forall a. Floating a => a -> a -> a
** a
5)) a -> a -> a
forall a. Num a => a -> a -> a
- (a
0.000195152832 a -> a -> a
forall a. Num a => a -> a -> a
* (a
x a -> a -> a
forall a. Floating a => a -> a -> a
** a
7))
sin_adenot_approximation :: Floating a => a -> a
sin_adenot_approximation :: forall a. Floating a => a -> a
sin_adenot_approximation a
x = a
0.391969947653056 a -> a -> a
forall a. Num a => a -> a -> a
* a
x a -> a -> a
forall a. Num a => a -> a -> a
* (a
forall a. Floating a => a
pi a -> a -> a
forall a. Num a => a -> a -> a
- a -> a
forall a. Num a => a -> a
abs a
x)
sin_robin_approximation :: Floating a => a -> a
sin_robin_approximation :: forall a. Floating a => a -> a
sin_robin_approximation a
x = let c :: a
c = a
x a -> a -> a
forall a. Num a => a -> a -> a
* a
0.01 in a
c a -> a -> a
forall a. Num a => a -> a -> a
* (a
2 a -> a -> a
forall a. Num a => a -> a -> a
- a
c)