Hi J./bugnoob,

There's a common mistake, which you might have made - not giving us enough information.

You don't mention "What OS?", for example. I guess it doesn't matter too much. The way we get input from the user and print the result differs greatly, but that's the easy part. Doing the calculation won't differ much between OSen. 64-bit code might delay overflow, but you'll still have to watch out for it.

My math is really rusty, but I think I can read the formula you link to. From n=0 to infinity... Well, I don't have time to get to infinity, but until we've got the accuracy the user asked for. I hope they're not going to be allowed to enter too large a number! We do x^n (x is going to be an integer... I hope!) and n! and divide.

I believe in starting really simple, so I started with x=1. 1^0 is 1, right? And 0! is 1(?). So 1, and increasing n gives 1/1 again, then 1/2 + 1/6 + 1/24 + 1/120 + 1/720... Yeah, that looks like it might be converging on e. The problem is that I resorted to a hand-held calculator to do it. An integer "div" is going to give a quotient of 0 and a remainder of 1 (half), then 0 and 1 (sixth), etc. Doesn't seem useful - we can't just add 'em into a register and call it our integral! Those coprocessor instructions would sure come in handy!

What does "only Nasm" mean? Not even allowed to use a linker? No libraries? Are you expected to write your own "bignum" routines? How much of this do you know how to do? Can you show us what you've got?

In any case, thanks for an interesting question!

Best,

Frank