Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Zhang Xiaomenghan
- -- Exercise 1.4
- -- | A module for working with triangles.
- module Hypotenuse where
- -- | Compute the length of the hypotenuse of a triangle from the lengths
- -- of its sides.
- hypotenuse :: Double -> Double -> Double
- hypotenuse a b = sqrt (square a + square b)
- -- | Square a number.
- square :: Num n => n -> n
- square x = x ^ 2
- -- | Law of cosine
- law_of_cosines :: Double -> Double -> Double -> Double
- law_of_cosines a b gamma = sqrt $ a^2 + b^2 - 2 * a * b * cos (gamma/180 * pi)
- SAMPLE RUNS IN GHCI:
- *Hypotenuse> law_of_cosines 4 5 6
- 1.1041395678396217
- Hypotenuse> law_of_cosines 1 1 60
- 0.9999999999999999
- *Hypotenuse> law_of_cosines 4 4 90
- 5.65685424949238
- *Hypotenuse> law_of_cosines 3 4 90
- 5.0
- *Hypotenuse> law_of_cosines 3 6 25
- 3.5175161217371276
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement