Jelajahi Sumber

chapter one exercises

George C. Privon 2 tahun lalu
induk
melakukan
a0ff87da44

+ 12 - 0
01-calculating/exercises/ex1.1

@@ -0,0 +1,12 @@
+```
+ghci> sin 30
+-0.9880316240928618
+```
+
+This is not equal to 0.5 because `sin` accepts arguments in radians.
+This gives the expected answer:
+
+```
+ghci> sin $ pi / 6
+0.49999999999999994
+```

+ 11 - 0
01-calculating/exercises/ex1.2

@@ -0,0 +1,11 @@
+a) 2 ^ 3 ^ 4 becomes:
+    2 ^ (3 ^ 4)
+
+b) 2 / 3 / 4 becomes:
+    (2/3)/4
+
+c) 7 - 5 / 4 becomes:
+    7 - (5/4)
+
+d) log 49 / 7 becomes:
+    (log 49 ) / 7

+ 6 - 0
01-calculating/exercises/ex1.3

@@ -0,0 +1,6 @@
+log2 32 in Haskell is:
+
+```
+ghci> logBase 2 32
+5.0
+```

+ 8 - 0
01-calculating/exercises/ex1.4

@@ -0,0 +1,8 @@
+(x, y) = (-3, 4) in polar coordinates:
+
+ghci> sqrt $ (-3)^2 + 4^2
+5.0
+ghci> atan2 4 (-3)
+2.214297435588181
+
+(r, theta) = (5, 2.214297435588181)

+ 2 - 0
01-calculating/exercises/ex1.5

@@ -0,0 +1,2 @@
+ghci> sqrt 7 ^ 2
+7.000000000000001

+ 1 - 0
01-calculating/exercises/ex1.6

@@ -0,0 +1 @@
+Having multiple (in)equality operators would constitute type errors because the evaluation of any one would evaluate to True/False and then that would be compared with whatever numeric type exists for the rest of the expression. That would be undefined.