based on my inspection,
print(Fraction(1, 2) * 2.1)
print(Fraction(1, 2) * complex(1 + 2j))
print(Fraction(1, 2) * Fraction(1, 2))
print(Decimal('0.5') * 2)
give,
1.05
(0.5+1j)
1/4
1.0
similarly,
print(Decimal('0.5') * 2.1)
print(Decimal('0.5') * complex(1 + 2j))
print(Decimal('0.5') * Fraction(1, 2))
should give,
1.05
(0.5+1j)
0.25 # or it could be made
# Decimal * Fraction gives 0.25,
# Fraction * Decimal gives 1/4
if we print the output without using print, then,
(Fraction(1, 2) * 2.1), (Fraction(1, 2) * complex(1 + 2j)), \
(Fraction(1, 2) * Fraction(1, 2))
gives,
(1.05, (0.5+1j), Fraction(1, 4))
and,
(Decimal('0.5') * 2)
gives,
Decimal('1.0')
similarly,
((Decimal('0.5') * 2.1), Decimal('0.5') * Fraction(1, 2))
should give,
(Decimal('1.05'), Decimal('0.25'))
plus,
Fraction(1, 2) * Decimal('0.5')
should give,
Fraction(1, 4)
for complex numbers it appears there is nothing like,
Decimal('1.2 + 2.1j')
so,
Decimal('0.5') * complex(1 + 2j)
is a bit confusing, but one possibility is to output,
(0.5 + 1j)
just like it works for Fraction
based on some further inspection, I noted down the types obtained after performing this multiplication for the valid cases,
arg1 | arg2 | result
-------------------------------
complex | complex | complex
complex | float | complex
complex | Fraction | complex
complex | int | complex
Decimal | Decimal | Decimal
Decimal | int | Decimal
float | float | float
float | Fraction | float
float | int | float
Fraction | Fraction | Fraction
Fraction | int | Fraction
int | int | int
just like float * Fraction
returns an object of type float
, and complex * Fraction
returns an object of type complex
, the same could be true for {float/complex} * Decimal