MCPcopy Create free account
hub / github.com/ccxt/ccxt / div

Method div

python/ccxt/base/precise.py:84–98  ·  view source on GitHub ↗
(self, other, precision=18)

Source from the content-addressed store, hash-verified

82 return Precise(integer_result, self.decimals + other.decimals)
83
84 def div(self, other, precision=18):
85 distance = precision - self.decimals + other.decimals
86 if distance == 0:
87 numerator = self.integer
88 elif distance < 0:
89 exponent = self.base ** -distance
90 numerator = self.integer // exponent
91 else:
92 exponent = self.base ** distance
93 numerator = self.integer * exponent
94 result, mod = divmod(numerator, other.integer)
95 # python floors negative numbers down instead of truncating
96 # if mod is zero it will be floored to itself so we do not add one
97 result = result + 1 if result < 0 and mod else result
98 return Precise(result, precision)
99
100 def add(self, other):
101 if self.decimals == other.decimals:

Callers 2

__truediv__Method · 0.95
string_divMethod · 0.45

Calls 1

PreciseClass · 0.70

Tested by

no test coverage detected