public
Description: The Nu programming language.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nu.git
Added exponentiation operator '**' and extra NuMath functions for 
rounding.
chapados (author)
Thu Jun 12 23:22:34 -0700 2008
commit  2b9142078ba11ee1732889a814f1a15dc1cceea5
tree    203a196841a24e47ebf60fae005d4569c94e1529
parent  c929ef38143d6ee23b5b1545f489fb8302d75539
...
594
595
596
 
597
598
 
599
 
 
600
 
 
 
 
 
601
602
603
...
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
0
@@ -594,10 +594,19 @@ extern id Nu__null;
0
 + (double) cos: (double) x {return cos(x);}
0
 + (double) sin: (double) x {return sin(x);}
0
 + (double) sqrt: (double) x {return sqrt(x);}
0
++ (double) cbrt: (double) x {return cbrt(x);}
0
 + (double) square: (double) x {return x*x;}
0
 + (double) exp: (double) x {return exp(x);}
0
++ (double) exp2: (double) x {return exp2(x);}
0
 + (double) log: (double) x {return log(x);}
0
++ (double) log2: (double) x {return log2(x);}
0
++ (double) log10: (double) x {return log10(x);}
0
 
0
++ (double) floor: (double) x {return floor(x);}
0
++ (double) ceil: (double) x {return ceil(x);}
0
++ (double) round: (double) x {return round(x);}
0
+
0
++ (double) raiseNumber: (double) x toPower: (double) y {return pow(x, y);}
0
 + (int) integerDivide:(int) x by:(int) y {return x / y;}
0
 + (int) integerMod:(int) x by:(int) y {return x % y;}
0
 
...
887
888
889
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
890
891
892
...
1864
1865
1866
 
1867
1868
1869
...
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
...
1882
1883
1884
1885
1886
1887
1888
0
@@ -887,6 +887,24 @@ limitations under the License.
0
 
0
 @end
0
 
0
+@interface Nu_exponentiation_operator : NuOperator {}
0
+@end
0
+
0
+@implementation Nu_exponentiation_operator
0
+- (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
0
+{
0
+ id cursor = cdr;
0
+ double result = [[[cursor car] evalWithContext:context] doubleValue];
0
+ cursor = [cursor cdr];
0
+ while (cursor && (cursor != Nu__null)) {
0
+ result = pow(result, [[[cursor car] evalWithContext:context] doubleValue]);
0
+ cursor = [cursor cdr];
0
+ }
0
+ return [NSNumber numberWithDouble:result];
0
+}
0
+
0
+@end
0
+
0
 @interface Nu_divide_operator : NuOperator {}
0
 @end
0
 
0
@@ -1864,6 +1882,7 @@ void load_builtins(NuSymbolTable *symbolTable)
0
     install("-", Nu_subtract_operator);
0
     install("*", Nu_multiply_operator);
0
     install("/", Nu_divide_operator);
0
+ install("**", Nu_exponentiation_operator);
0
     install("%", Nu_modulus_operator);
0
     install("&", Nu_bitwiseand_operator);
0
     install("|", Nu_bitwiseor_operator);
...
12
13
14
 
 
 
 
15
16
17
...
27
28
29
 
 
 
 
 
30
31
32
...
35
36
37
 
 
 
 
 
 
 
 
38
39
40
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
43
44
...
51
52
53
 
 
 
 
 
 
54
55
56
57
58
 
59
60
61
...
63
64
65
66
 
67
68
69
70
 
71
72
73
74
 
75
76
77
...
92
93
94
95
 
96
97
98
...
12
13
14
15
16
17
18
19
20
21
...
31
32
33
34
35
36
37
38
39
40
41
...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
...
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
106
107
108
 
109
110
111
112
 
113
114
115
116
 
117
118
119
120
...
135
136
137
 
138
139
140
141
0
@@ -12,6 +12,10 @@
0
           (assert_equal 1 (NuMath exp:0))
0
           (assert_in_delta E (NuMath exp:1) 0.001))
0
      
0
+ (imethod (id) testExp2 is
0
+ (assert_equal 1 (NuMath exp2:0))
0
+ (assert_in_delta 2 (NuMath exp2:1) 0.001))
0
+
0
      (imethod (id) testCos is
0
           (assert_in_delta -1 (NuMath cos:PI) 0.001)
0
           (assert_equal 1 (NuMath cos:0))
0
@@ -27,6 +31,11 @@
0
           (assert_equal 1.5 (NuMath sqrt:2.25))
0
           (assert_in_delta 1.732 (NuMath sqrt:3) 0.001))
0
      
0
+ (imethod (id) testCbrt is
0
+ (assert_equal 0 (NuMath cbrt:0))
0
+ (assert_equal 1.5 (NuMath cbrt:3.375))
0
+ (assert_in_delta 1.587 (NuMath cbrt:4) 0.001))
0
+
0
      (imethod (id) testSquare is
0
           (assert_equal 49 (NuMath square:7))
0
           (assert_equal 20.25 (NuMath square:4.5)))
0
@@ -35,10 +44,37 @@
0
           (assert_equal 0 (NuMath log:1))
0
           (assert_in_delta 2 (NuMath log:(* E E)) 0.001))
0
      
0
+ (imethod (id) testLog2 is
0
+ (assert_equal 0 (NuMath log2:1))
0
+ (assert_in_delta 2 (NuMath log2:(* 2 2)) 0.001))
0
+
0
+ (imethod (id) testLog10 is
0
+ (assert_equal 0 (NuMath log10:1))
0
+ (assert_in_delta 2 (NuMath log10:(* 10 10)) 0.001))
0
+
0
      (imethod (id) testAbs is
0
           (assert_equal 6 (NuMath abs:6))
0
           (assert_equal PI (NuMath abs:(- 0 PI))))
0
      
0
+ (imethod (id) testFloor is
0
+ (assert_equal 9 (NuMath floor:9.99))
0
+ (assert_equal -10 (NuMath floor:-9.99))
0
+ (assert_equal 3 (NuMath floor:PI))
0
+ (assert_equal -4 (NuMath floor:(- 0 PI))))
0
+
0
+ (imethod (id) testCeil is
0
+ (assert_equal 10 (NuMath ceil:9.99))
0
+ (assert_equal -9 (NuMath ceil:-9.99))
0
+ (assert_equal 4 (NuMath ceil:PI))
0
+ (assert_equal -3 (NuMath ceil:(- 0 PI))))
0
+
0
+ (imethod (id) testRound is
0
+ (assert_equal 10 (NuMath round:9.99))
0
+ (assert_equal 10 (NuMath round:9.5))
0
+ (assert_equal -10 (NuMath round:-9.99))
0
+ (assert_equal 3 (NuMath round:PI))
0
+ (assert_equal -3 (NuMath round:(- 0 PI))))
0
+
0
      (imethod (id) testIntegerDivide is
0
           (assert_equal 3 (NuMath integerDivide:10 by:3))
0
           (assert_equal 4 (NuMath integerDivide:17 by:4))
0
@@ -51,11 +87,18 @@
0
           (assert_equal 0 (NuMath integerMod:16 by:4))
0
           (assert_equal -11 (NuMath integerMod:-50 by:13)))      ;; questionable
0
      
0
+ (imethod (id) testRaiseNumber is
0
+ (assert_equal 1 (NuMath raiseNumber:10 toPower:0))
0
+ (assert_equal 169 (NuMath raiseNumber:13 toPower:2))
0
+ (assert_equal 8 (NuMath raiseNumber:64 toPower:0.5))
0
+ (assert_equal 0.5 (NuMath raiseNumber:4 toPower:-0.5)))
0
+
0
      (imethod (id) testArithmeticOperators is
0
           (assert_equal 4   (+ 2 2))
0
           (assert_equal 15   (- 20 5))
0
           (assert_equal 20   (* 2 2 5))
0
           (assert_equal 13   (/ 26 2))
0
+ (assert_equal 64 (** 8 2))
0
           (assert_equal 7  (% 47 8))
0
           (assert_equal 4   (& 7 12))
0
           (assert_equal 15   (| 7 12)))
0
@@ -63,15 +106,15 @@
0
      (imethod (id) testComparisonOperators is
0
           (assert_equal nil (> 10 20))
0
           (assert_equal nil (> 20 20))
0
- (assert_equal t (> 30 20))
0
+ (assert_equal t (> 30 20))
0
           
0
           (assert_equal t (< 10 20))
0
           (assert_equal nil (< 20 20))
0
- (assert_equal nil (< 30 20))
0
+ (assert_equal nil (< 30 20))
0
           
0
           (assert_equal nil (>= 10 20))
0
           (assert_equal t (>= 20 20))
0
- (assert_equal t (>= 30 20))
0
+ (assert_equal t (>= 30 20))
0
           
0
           (assert_equal t (<= 10 20))
0
           (assert_equal t (<= 20 20))
0
@@ -92,7 +135,7 @@
0
      
0
      (imethod (id) testBooleanOperators is
0
           (assert_equal nil (and 1 2 3 0))
0
- (assert_equal 4 (and 1 2 3 4))
0
+ (assert_equal 4 (and 1 2 3 4))
0
           
0
           (assert_equal nil (or 0 nil 0 0))
0
           (assert_equal 4 (or 0 nil 4 0))

Comments

    No one has commented yet.