I was trying to understand the math behind calculations using / and // and % operators by doing some trials and found the results are similar to calculator only when using Decimal() but without it the results kinda confusing, i tried to add comments #No Idea
to my code to mark the points i don't understand,for example:
in this trial for % operator by applying signed and unsigned number the results and with and without Decimal() the results are :
>>> 9%5 #This result will be the reminder 4 >>> (-9)%5 #No Idea 1 >>> Decimal(9)% Decimal(5) #This result will be the reminder Decimal('4') >>> Decimal(-9)% Decimal(5) #The result will be the signed reminder Decimal('-4')
in this trial for // operator and using signed and unsigned number with and without Decimal() the results are :
>>> 9//5 #int result 1 >>> -9//5 #No Idea -2 >>> Decimal(9)/Decimal(5) #Same result as using calculator Decimal('1.8') >>> Decimal(-9)//Decimal(5) #No Idea Decimal('-1')
Please consider that this question is not a duplicate and i have done some research to get an answer but i found some answered questions that explain only about // operator using only positive signed numbers and doesn't include information about negative signed numbers or using the Decimal() and doesn't have answer about % operator.
so,It will be helpful if someone knows why the results are different and how they are calculated.