Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
bfc1b529
Commit
bfc1b529
authored
Jan 23, 2012
by
Peter Eastman
Browse files
Define both __div__ and __truediv__ to work on all Python versions
parent
d648613b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
0 deletions
+7
-0
wrappers/python/simtk/unit/quantity.py
wrappers/python/simtk/unit/quantity.py
+4
-0
wrappers/python/simtk/unit/unit.py
wrappers/python/simtk/unit/unit.py
+2
-0
wrappers/python/simtk/unit/unit_operators.py
wrappers/python/simtk/unit/unit_operators.py
+1
-0
No files found.
wrappers/python/simtk/unit/quantity.py
View file @
bfc1b529
...
@@ -383,6 +383,8 @@ class Quantity(object):
...
@@ -383,6 +383,8 @@ class Quantity(object):
return
self
*
pow
(
other
,
-
1.0
)
return
self
*
pow
(
other
,
-
1.0
)
# return Quantity(self._value / other, self.unit)
# return Quantity(self._value / other, self.unit)
__div__
=
__truediv__
def
__rtruediv__
(
self
,
other
):
def
__rtruediv__
(
self
,
other
):
"""Divide a scalar by a quantity.
"""Divide a scalar by a quantity.
...
@@ -398,6 +400,8 @@ class Quantity(object):
...
@@ -398,6 +400,8 @@ class Quantity(object):
return
other
*
pow
(
self
,
-
1.0
)
return
other
*
pow
(
self
,
-
1.0
)
# return Quantity(other / self._value, pow(self.unit, -1.0))
# return Quantity(other / self._value, pow(self.unit, -1.0))
__rdiv__
=
__rtruediv__
def
__pow__
(
self
,
exponent
):
def
__pow__
(
self
,
exponent
):
"""Raise a Quantity to a power.
"""Raise a Quantity to a power.
...
...
wrappers/python/simtk/unit/unit.py
View file @
bfc1b529
...
@@ -187,6 +187,8 @@ class Unit(object):
...
@@ -187,6 +187,8 @@ class Unit(object):
"""
"""
return
self
*
pow
(
other
,
-
1
)
return
self
*
pow
(
other
,
-
1
)
__div__
=
__truediv__
# def __rtruediv__(self, other):
# def __rtruediv__(self, other):
# Because rtruediv returns a Quantity, look in quantity.py for definition of Unit.__rtruediv__
# Because rtruediv returns a Quantity, look in quantity.py for definition of Unit.__rtruediv__
...
...
wrappers/python/simtk/unit/unit_operators.py
View file @
bfc1b529
...
@@ -44,6 +44,7 @@ def _unit_class_rdiv(self, other):
...
@@ -44,6 +44,7 @@ def _unit_class_rdiv(self, other):
return
Quantity
(
value
,
unit
).
reduce_unit
(
self
)
return
Quantity
(
value
,
unit
).
reduce_unit
(
self
)
Unit
.
__rtruediv__
=
_unit_class_rdiv
Unit
.
__rtruediv__
=
_unit_class_rdiv
Unit
.
__rdiv__
=
_unit_class_rdiv
def
_unit_class_mul
(
self
,
other
):
def
_unit_class_mul
(
self
,
other
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment