[Sugar-devel] [PATCH] Calculate/functions.py

James Cameron quozl at laptop.org
Wed Jun 2 23:38:54 EDT 2010


G'day Tim,

Good stuff.  But please consider this patch on top of your current
patch.  It does this:

1.  removes the assertion of your copyright ... none of the other files
contain a copyright assertion, and so they don't properly comply with
the guidance in COPYING "How to Apply These Terms to Your New Programs",
but the files do imply authorship, ... I think they should all contain a
copyright, what do you think?

2.  removes many of the whitespace errors introduced,

3.  fixes a call to self.is_int() in mod(), which currently causes mod()
to fail in Calculate,

4.  fixes two calls to d() instead of _d(), which currently cause
shift_left() to fail in Calculate,

5.  fixes a transcription error from the XOR Wikipedia article by
editing out a symbol that can't be represented in code.

Another question for you ... is the docstring of sinc() supposed to have
two periods trailing the formula?

Based on my edits, reviewed.

-- 
James Cameron
http://quozl.linux.org.au/
-------------- next part --------------
diff --git a/functions.py b/functions.py
index 996307d..0db019d 100644
--- a/functions.py
+++ b/functions.py
@@ -1,12 +1,9 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
-
 # functions.py, functions available in Calculate,
 # by Reinier Heeres <reinier at heeres.eu>
 #
-# Copyright 2010 Tim McNamara <tim at sugarlabs.org>
-
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or
@@ -224,9 +221,7 @@ def atanh(x):
 atanh.__doc__ = _(atanh.__doc__)
 
 def ceil(x):
-    """#!/usr/bin/python
-          # -*- coding: <encoding name> -*-
-
+    """
     Finds the smallest integer larger than x.
 
     >>> ceil(1.1)
@@ -367,7 +362,7 @@ def factorize(x, mode='string'):
 
     If mode='string', return a string representing the factors:
        For example: 15 => "3 * 5".
-    
+
     >>> factorize(15)
     '3 * 5'
     >>> factorize(90, mode='list')
@@ -424,7 +419,7 @@ def is_int(n):
     Determines whether n is an integer.
 
     Returns True if it is, or False if not.
-    
+
     >>> is_int(1)
     True
     >>> is_int(_Decimal('1'))
@@ -474,7 +469,7 @@ def log10(x):
 log10.__doc__ = _(log10.__doc__)
 
 def mod(x, y):
-    if self.is_int(y):
+    if is_int(y):
         return x % y
     else:
         raise TypeError(_('Can only calculate x modulo <integer>'))
@@ -571,7 +566,7 @@ def shift_left(x, y):
     (Multiply by 2 per bit)
     """
     if is_int(x) and is_int(y):
-        return d(int(x) << int(y))
+        return _d(int(x) << int(y))
     else:
         raise TypeError(_('Bitwise operations only apply to integers'))
 shift_left.__doc__ = _(shift_left.__doc__)
@@ -583,7 +578,7 @@ def shift_right(self, x, y):
     (Multiply by 2 per bit)
     """
     if is_int(x) and is_int(y):
-        return d(int(x) >> int(y))
+        return _d(int(x) >> int(y))
     else:
         raise TypeError(_('Bitwise operations only apply to integers'))
 shift_right.__doc__ = _(shift_right.__doc__)
@@ -592,7 +587,7 @@ def sin(x):
     """
     Calculates the sine of x.
     This is the y-coordinate on the unit circle at the angle x.
-    
+
     See also http://en.wikipedia.org/wiki/Sine
     """
     return math.sin(_scale_angle(x))
@@ -600,9 +595,9 @@ sin.__doc__ = _(sin.__doc__)
 
 def sinh(x):
     """
-    Calculates the hyperbolic sine of x, given by 
+    Calculates the hyperbolic sine of x, given by
         (exp(x) - exp(-x)) / 2
-        
+
     See also http://en.wikipedia.org/wiki/Hyperbolic_sine
     """
     return math.sinh(x)
@@ -611,10 +606,10 @@ sinh.__doc__ = _(
 
 def sinc(x):
     """
-    Calculates the sinc of x, given by sin(x) / x.. 
-    
+    Calculates the sinc of x, given by sin(x) / x..
+
     From http://en.wikipedia.org/wiki/Sinc
-        The term "sinc" is a contraction of the function's 
+        The term "sinc" is a contraction of the function's
         full Latin name, the sinus cardinalis (cardinal sine).
     """
     if float(x) == 0.0:
@@ -625,9 +620,9 @@ sinc.__doc__ = _(sinc.__doc__)
 def sqrt(x):
     """
     Find the square root of x.
-    
+
     The square root is the number whose square equals x.
-    
+
     See also http://en.wikipedia.org/wiki/Square_root
 
     >>> sqrt(16)
@@ -652,10 +647,10 @@ sub.__doc__ = _(sub.__doc__)
 def tan(x):
     """
     Calculates the tangent of x, by sin(x) / cos(x).
-    
-    This is the slope of the line from the origin of the unit 
+
+    This is the slope of the line from the origin of the unit
     circle to the point on the unit circle defined by the angle x.
-    
+
     >>> tan(0.1)
     0.10033467208545055
     """
@@ -665,9 +660,9 @@ tan.__doc__ = _(tan.__doc__)
 def tanh(x):
     """
     Calculates the hyperbolic tangent of x. Given by sinh(x) / cosh(x)
-    
+
     See also http://en.wikipedia.org/wiki/Hyperbolic_tangent
-    
+
     >>> tanh(0.1)
     0.099667994624955819
     """
@@ -677,7 +672,7 @@ tanh.__doc__ = _(tanh.__doc__)
 def xor(x, y):
     """
     XOR tests whether x or y is true, but doesn't allow both.
-    
+
     >>> xor(x=True, y=False)
     True
     >>> xor(x=False, y=True)
@@ -686,11 +681,11 @@ def xor(x, y):
     False
     >>> xor(x=False, y=False)
     False
-    
+
     Adapted from http://en.wikipedia.org/wiki/Exclusive_or:
-        The logical operation "exclusive disjunction", also called 
-        exclusive or (symbolized XOR, EOR, EXOR, or ???), is a type 
-        of logical disjunction on two operands that results in a 
+        The logical operation "exclusive disjunction", also called
+        exclusive or (symbolized XOR, EOR, or EXOR), is a type
+        of logical disjunction on two operands that results in a
         value of true if exactly one of the operands has a value of true.
     """
     return x ^ y


More information about the Sugar-devel mailing list