MCPcopy Index your code
hub / github.com/python/cpython / from_decimal

Method from_decimal

Lib/fractions.py:350–359  ·  view source on GitHub ↗

Converts a finite Decimal instance to a rational number, exactly.

(cls, dec)

Source from the content-addressed store, hash-verified

348
349 @classmethod
350 def from_decimal(cls, dec):
351 """Converts a finite Decimal instance to a rational number, exactly."""
352 from decimal import Decimal
353 if isinstance(dec, numbers.Integral):
354 dec = Decimal(int(dec))
355 elif not isinstance(dec, Decimal):
356 raise TypeError(
357 "%s.from_decimal() only takes Decimals, not %r (%s)" %
358 (cls.__name__, dec, type(dec).__name__))
359 return cls._from_coprime_ints(*dec.as_integer_ratio())
360
361 @classmethod
362 def _from_coprime_ints(cls, numerator, denominator, /):

Callers 1

testFromDecimalMethod · 0.80

Calls 3

as_integer_ratioMethod · 0.95
DecimalClass · 0.90
_from_coprime_intsMethod · 0.80

Tested by 1

testFromDecimalMethod · 0.64