Coding my way out of a brown paper bag
Jul. 10th, 2003 11:52 amThe language we're writing a compiler for has primitive support for complex numbers. Our current front-end is pretty much entirely my project, and one of our summer undergrads has been putting a lot of abuse on it -- a good thing, since some of our code doesn't get tested otherwise.
Today's bug: if you declare complex c = 1-2i;, the parser splits it into two parts, 1 - (0+2i). The complex-handling code then says, "aha! Binary expression! The first part is purely real, and the second is purely imaginary, so I take the real part from the first and the imaginary part from the second, and get 1+2i. All done!" See, nobody actually needs the bottom half of the complex plane for anything...
Today's bug: if you declare complex c = 1-2i;, the parser splits it into two parts, 1 - (0+2i). The complex-handling code then says, "aha! Binary expression! The first part is purely real, and the second is purely imaginary, so I take the real part from the first and the imaginary part from the second, and get 1+2i. All done!" See, nobody actually needs the bottom half of the complex plane for anything...