daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. asinℝp :: (Fractional a, Ord a) => Fastℕ -> a -> a
  2. asinℝp precision x
  3.   | x>0 = res
  4.   | x < 0 = 0-res
  5.   | otherwise = 0
  6.     where
  7.       res=(abs x)+(sum [asinTerm (abs x) (toInteger i) | i <- [1..precision]])
  8.  
  9. asinTerm :: (Fractional a) => a -> ℕ -> a
  10. asinTerm x n = ((x^oddTerm) *(fromIntegral $ factorialskip (oddTerm-2))) / (fromIntegral $ (factorialskip (evenTerm))*(oddTerm))
  11.   where
  12.     oddTerm :: ℕ
  13.     oddTerm = 2*n + 1
  14.     evenTerm :: ℕ
  15.     evenTerm = 2*n
  16.  
  17. factorialskip :: ℕ -> ℕ
  18. factorialskip 0 = 1
  19. factorialskip 1 = 1
  20. factorialskip n = n * factorialskip (n-2)
  21.  
  22. cosℝp :: (Fractional a) => Fastℕ -> a -> a
  23. cosℝp precision x = 1-(sum [cosTerm x (toInteger i) | i <- [1..precision]])
  24.  
  25. cosTerm :: (Fractional a) => a -> ℕ -> a
  26. cosTerm x i = (x^evenTerm / fromIntegral (factorial evenTerm))*(-1)^(i-1)
  27.   where evenTerm = 2*i
  28.  
  29. sinℝp :: (Fractional a) => Fastℕ -> a -> a
  30. sinℝp precision x = sum [sinTerm x (toInteger i) | i <- [1..precision]]
  31.  
  32. sinTerm :: (Fractional a) => a -> ℕ -> a
  33. sinTerm x i = (x^oddTerm / fromIntegral (factorial oddTerm))*(-1)^(i-1)
  34.   where oddTerm = 2*i - 1
  35.  
  36. factorial :: ℕ -> ℕ
  37. factorial 1 = 1
  38. factorial n = n * factorial (n-1)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top