calculator now works with negative number

thanks to the modified algorithm!