Calculate e^x and ln(x) Given a floating point x (x&lt;100), return e^x and ln(x). The first 6 decimal places of the number have to be right, but any others after do not have to be correct.

You cannot have any "magic" constants explicitly stated (e.x. a=1.35914 since 1.35914*2 ~= e), but you can calculate them. Only use +, -, *, and / for arithmetic operators.

If x is less than or equal to 0, output ERROR instead of the intended value of ln(x).

Test Cases:

input: 2
output: 7.389056 0.693147
input: 0.25
output: 1.284025 -1.386294
input: 2.718281828
output: 15.154262 0.999999  (for this to output correctly, don't round to 6 places)
input: -0.1
output: 0.904837 ERROR


Shortest code wins.
PHP 109 107 bytes

&lt;?for($g=1e4;--$g;$l=$y/$g+abs($y=$x&gt;1?1-1/$x:$x-1)*$l)$e=1+$e/$g*$x.=fgets(STDIN);echo"$e ",$x&gt;0?$l:ERROR;


 is a fairly straight-forward calculation. I use a nested form of the sum of inverse factorials, which not only increases the convergence rate, but also allows for exponentiation at the same time:



 is slightly more complicated. All convergent series seem to work for  or , but not both (Newton's iteration does not have this limitation, but requires the calculation of  each step). This isn't really a problem, though, given the log identity:



This means that if, for example, the iteration you're using only works on  and , you can use the multiplicative inverse of  and negate the result. Because I was using a nested identity for , I also chose to use a nested identity for :

 where 

Or equivalently, as demonstrated by Paul Walls' implementation:



I define the  case as  (which is necessarily negative), using the absolute value for the inner product, and then allowing a bare  value in the fraction to correct the sign.

Sample I/O:

$ echo 2 | php exp_ln.php
7.3890560989307 0.69314718055995

$ echo 0.25 | php exp_ln.php
1.2840254166877 -1.3862943611199

$ echo 2.718281828 | php exp_ln.php
15.154262234523 0.99999999983113

$ echo -0.1 | php exp_ln.php
0.90483741803596 ERROR




Perl 95 93 89 bytes

$e=1+$e/$?*($x.=&lt;&gt;),$l=$_/$?+$l*abs,$_=$x&gt;1?1-1/$x:$x-1while--$?;print"$e ",$x&gt;0?$l:ERROR


Nearly identical to the PHP solution above, with a slightly larger iteration (65535 down to 0).

Edits:


Both 2 byte improvements due to Paul Walls.
Four more bytes saved in Perl by (ab)using $?, which is stored internally as an unsigned short, and by using $_ to save parentheses in abs.