Adding +-, sq, sqrt, and ! operations
authorepage <eopage@byu.net>
Tue, 28 Apr 2009 02:53:45 +0000 (02:53 +0000)
committerepage <eopage@byu.net>
Tue, 28 Apr 2009 02:53:45 +0000 (02:53 +0000)
git-svn-id: file:///svnroot/ejpi/trunk@31 df6cc7de-23d0-4ae0-bb86-c17aa67b2a9d

src/plugins/builtins.map
src/plugins/builtins.py

index 59170a0..45af6d6 100644 (file)
@@ -9,7 +9,9 @@
                (0, 1): {
                        "CENTER": {"action": "8", "type": "text", "text": "8", },
                        "SOUTH": {"action": "[**]", "type": "text", "text": "**", },
-                       "showAllSlices": True,
+                       "EAST": {"action": "[sq]", "type": "text", "text": "sq", },
+                       "WEST": {"action": "[sqrt]", "type": "text", "text": "sqrt", },
+                       "showAllSlices": False,
                },
                (0, 2): {
                        "CENTER": {"action": "9", "type": "text", "text": "9", },
@@ -38,6 +40,7 @@
                },
                (2, 2): {
                        "CENTER": {"action": "3", "type": "text", "text": "3", },
+                       "WEST": {"action": "[!]", "type": "text", "text": "!", },
                        "showAllSlices": True,
                },
                (3, 0): {
@@ -58,6 +61,7 @@
                (3, 2): {
                        "CENTER": {"action": ".", "type": "text", "text": ".", },
                        "NORTH": {"action": "j", "type": "text", "text": "j", },
+                       "WEST": {"action": "[+-]", "type": "text", "text": "+/-", },
                        "showAllSlices": True,
                },
        },
index 5ef3b90..d464e9d 100644 (file)
@@ -26,7 +26,20 @@ PLUGIN.register_operation("/", trueDivision)
 
 exponentiation = operation.generate_function(operator.pow, "**", operation.Function.REP_INFIX, 2)
 abs = operation.generate_function(operator.abs, "abs", operation.Function.REP_FUNCTION, 1)
-#factorial = operation.generate_function(math.factorial, "!", operation.Function.REP_POSTFIX, 1)
-
+try:
+       fact_func = math.factorial
+except AttributeError:
+       def fact_func(num):
+               return num * fact_func(num - 1)
+factorial = operation.generate_function(math.factorial, "!", operation.Function.REP_POSTFIX, 1)
+negate = operation.generate_function(operator.neg, "+-", operation.Function.REP_PREFIX, 1)
+square = operation.generate_function((lambda self, x: x ** 2), "sq", operation.Function.REP_FUNCTION, 1)
+square_root = operation.generate_function((lambda self, x: x ** 0.5), "sqrt", operation.Function.REP_FUNCTION, 1)
+
+# @todo Possibly make a graphic for this of x^y
 PLUGIN.register_operation("**", exponentiation)
 PLUGIN.register_operation("abs", abs)
+PLUGIN.register_operation("!", factorial)
+PLUGIN.register_operation("+-", negate)
+PLUGIN.register_operation("sq", square)
+PLUGIN.register_operation("sqrt", square_root)