Added sgn(x) to .calc

Fri, 24 Apr 2015 06:40:08 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Fri, 24 Apr 2015 06:40:08 +0300
changeset 131
7349e9c6176b
parent 130
c82cef747008
child 132
a22c50f52a23

Added sgn(x) to .calc

calc.py file | annotate | diff | comparison | revisions
--- a/calc.py	Sun Apr 19 22:46:39 2015 +0300
+++ b/calc.py	Fri Apr 24 06:40:08 2015 +0300
@@ -134,6 +134,9 @@
 	else:
 		OperatorSymbols[op.symbol] = [op]
 
+def sgn (x):
+	return cmp (x, 0)
+
 Constants = {
 	'pi': cmath.pi,
 	'e': cmath.e,
@@ -177,6 +180,7 @@
 	'im':		{ 'function': lambda x: x.imag },
 	'conjugate':{ 'function': lambda x: x.conjugate() },
 	'rand':		{ 'function': random.random },
+	'sgn':		{ 'function': realf (sgn) },
 }
 
 Tokens = ['(', ')']

mercurial