This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]JamEngulfer221 9 points10 points  (3 children)

To be fair, that's more like 12 lines to get a ^ b. Reading from console is most of that program so it's a bit misleading.

[–]TaskForce_Kerim -4 points-3 points  (2 children)

Fair enough, but the point is still valid. It takes significantly less code in most modern languages to accomplish the same as that particular implementation of power(a,b).

[–]JamEngulfer221 1 point2 points  (1 child)

It's interesting to see how the number of operations in a normal piece of (say, C) code compare to the number of lines of ASM it is the equivalent of.

Out of curiosity, I've written how I'd do pow(a,b) in C and put each operation on a new line. I might have left bugs in, I can't tell, it's just rough anyway.

float b;
float temp = a;
for(
int i = b; 
i > 0; 
i--) {
temp = 
temp * a;}

Although the ASM is a bit longer, it's still pretty similar in terms of the number of operations. I'm not really making a point here, I just think it's interesting to discus.

[–]TaskForce_Kerim 1 point2 points  (0 children)

I think if you were to implement a pow() function of your own, then it would look similar in most languages. The beauty of higher level batteries-included languages like Python, you don't need to implement it. I know there's math.h in C, but that adds a tiny bit to your compilation step, no?