The bug only shows when you try to calculate the modulus of negative values.
#!/usr/bin/perl $A = 106; printf("Division\n"); printf("106 / 10 = 10\t<- expected\n"); printf("%d / 10 = %01d\t<- correct\n", $A, $A / 10); printf("\n"); printf("Modulus\n"); printf("106 %% 10 = 6\t<- expected\n"); printf("%d %% 10 = %d\t<- correct\n", $A, $A % 10); printf("\n\nNegative values\n"); $A = -106; printf("Division\n"); printf("%d / 10 = 10\t<- expected\n", $A); printf("%d / 10 = %01d\t<- correct\n", $A, $A / 10); printf("\n"); printf("Modulus\n"); printf("%d %% 10 = -6\t<- expected\n", $A); printf("%d %% 10 = %d\t<- WHAT THE!!!\n", $A, $A % 10);
This is the output.
Division 106 / 10 = 10 <- expected 106 / 10 = 10 <- correct Modulus 106 % 10 = 6 <- expected 106 % 10 = 6 <- correct Negative values Divsion -106 / 10 = 10 <- expected -106 / 10 = -10 <- correct Modulus -106 % 10 = -6 <- expected -106 % 10 = 4 <- WHAT THE!!!