pow(float x, float y) in RISC Assembly

53 views Asked by At

I am writing a compiler for a variation of Fortran to MIPS as an assignment for the University.

In that language, power operator is built-in, exactly like Python where you can say a ** b and it's done.

So, in some point I have to write assembly for the pow function.

Of course, pow(int x, int y) is easy, as pow(float x, int y) is easy, but what happens when the exponent is float? How do I calculate that given my instruction set can only give me addition, subtraction, multiplication and division?

I have think of Taylor series, but how could I implement that? I am not so sure.

Let's say I take the 3rd order Taylor's polynomial around a fixed point (x0, y0), won't that approximation be really bad for points far from (x0, y0)?

I need an easy and simple way to do that, because that's a toy compiler, not a scientific one with real use cases, it has no optimizations etc.

Moreover, I don't really know what it should do when the the base is negative and the exponent is a fraction, let's say 1/2 where the result is a complex number (language supports complex numbers).

So, please give me your sights. Thanks in advance.

0

There are 0 answers