Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __sub__(self, other):
res = super(UncertainQuantity, self).__sub__(other)
u = (self.uncertainty**2+other.uncertainty**2)**0.5
return UncertainQuantity(res, uncertainty=u, copy=False)
def _cd(name):
entry = physical_constants[name]
if False: #entry['precision']:
return UncertainQuantity(
entry['value'], entry['units'], entry['precision']
)
else:
return Quantity(entry['value'], entry['units'])
def __truediv__(self, other):
res = super(UncertainQuantity, self).__truediv__(other)
try:
sru = self.relative_uncertainty
oru = other.relative_uncertainty
ru = (sru**2+oru**2)**0.5
u = res.view(Quantity) * ru
except AttributeError:
other = np.array(other, copy=False, subok=True)
u = (self.uncertainty**2/other**2)**0.5
res._uncertainty = u
return res
def __rsub__(self, other):
if not isinstance(other, UncertainQuantity):
other = UncertainQuantity(other, copy=False)
return UncertainQuantity.__sub__(other, self)
def rescale(self, units):
cls = UncertainQuantity
ret = super(cls, self).rescale(units).view(cls)
ret.uncertainty = self.uncertainty.rescale(units)
return ret
def _reference(self):
ret = super(UncertainQuantity, self)._reference.view(UncertainQuantity)
ret.uncertainty = self.uncertainty._reference
return ret
def __rsub__(self, other):
if not isinstance(other, UncertainQuantity):
other = UncertainQuantity(other, copy=False)
return UncertainQuantity.__sub__(other, self)
# -*- coding: utf-8 -*-
"""
"""
from __future__ import absolute_import
from ._utils import _cd
from ..uncertainquantity import UncertainQuantity
from ..unitquantity import UnitConstant
au = astronomical_unit = UnitConstant(
'astronomical_unit',
UncertainQuantity(149597870700, 'm', 3),
symbol='au',
doc='http://en.wikipedia.org/wiki/Astronomical_unit'
)
G = Newtonian_constant_of_gravitation = UnitConstant(
'Newtonian_constant_of_gravitation',
_cd('Newtonian constant of gravitation'),
symbol='G'
)
del UnitConstant, UncertainQuantity, _cd
def __add__(self, other):
res = super(UncertainQuantity, self).__add__(other)
u = (self.uncertainty**2+other.uncertainty**2)**0.5
return UncertainQuantity(res, uncertainty=u, copy=False)
def __rsub__(self, other):
if not isinstance(other, UncertainQuantity):
other = UncertainQuantity(other, copy=False)
return UncertainQuantity.__sub__(other, self)