コード例 #1
0
 def __rtruediv__(self, other):
     if phf.is_nan(other):
         return other
     if isinstance(other, NUMBER):
         new_value = other / self.value
         new_dimensions = vec.multiply(self.dimensions, -1)
         new_factor = self.factor**-1  # added new_factor
         return Physical(
             new_value,
             new_dimensions,
             new_factor,  # updated from self.factor to new_factor
             self.precision,
         )
     else:
         try:
             return Physical(
                 other / self.value,
                 vec.multiply(self.dimensions, -1),
                 self.factor**-1,  # updated to ** -1
                 self.precision,
             )
         except:
             raise ValueError(
                 f"Cannot divide between {other} and {self}: " +
                 ".value attributes are incompatible.")
コード例 #2
0
def test_multiply():
    assert vec.multiply(P1, P3) == Point(x=2.0, y=3.4, z=0.0)
    assert vec.multiply(D2, D3) == Dimensions(kg=2.0,
                                              m=4.0,
                                              s=8.0,
                                              A=0.0,
                                              cd=0.0,
                                              K=0.0,
                                              mol=0.0)
    assert vec.multiply(P3, 3.5) == Point(x=3.5, y=3.5, z=0)
コード例 #3
0
 def __pow__(self, other):
     if isinstance(other, NUMBER):
         if self.prefixed:
             return float(self)**other
         new_value = self.value**other
         new_dimensions = vec.multiply(self.dimensions, other)
         new_factor = self.factor**other
         return Physical(new_value, new_dimensions, new_factor,
                         self.precision)
     else:
         raise ValueError("Cannot raise a Physical to the power of \
                                  another Physical -> ({self}**{other})".
                          format(self, other))
コード例 #4
0
def _check_dims_parallel(d1: Dimensions, d2: Dimensions) -> bool:
    """
    Returns True if d1 and d2 are parallel vectors. False otherwise.
    """
    return vec.multiply(d1, vec.dot(d2,
                                    d2)) == vec.multiply(d2, vec.dot(d1, d2))