Why does the expression exp(i*pi) return the wrong result in GNU Octave?

This isn't a bug with either, but due to the way computers perform floating point operations. There is a limited amount of precision any computer can operate with, and so you will sometimes see anomalies like this. While it is possible to write software that can handle this, it would take a lot more computation time and drastically increase memory requirements.

If you look at it, e^(i*pi) returns -1 + 1.2x10^-16i. As you can see, the imaginary component is extremely small (most would consider it negligible, since it's 16 orders of magnitude smaller then the real part). This component is introduced by rounding and precision errors, both with the calculation itself, as well as the stored value of pi since it's irrational (see this link for another example dealing with irrational numbers).

If this calculation error is unacceptable, you should look into math packages which perform symbolic rather then numerical analysis, or ones that use high-precision floating point numbers. The caveats of these are that they will drastically increase your memory requirements, and symbolic analysis is often much slower. Also, higher precision numbers will just shrink the magnitude of the rounding/precision errors, not eliminate them.