Talk:Exponentiation operator

From Rosetta Code

Fractional Exponents

This is for integer powers only right? No fractional exponents? --Mwn3d 05:58, 19 February 2008 (MST)

I believe that the REAL * REAL fraction can probably be done faster using some numerical equation. Eg simply

OP ** = ( REAL base, exponent )REAL: exp(log(base)*exponent); ~ # ... #

This above would work for fractional powers. For integral exponents the routine I provided is "sometimes" faster then alternatives, esp where the exponent is s power of two.

BTW: I wrote these routine as a hint to User:Short Circuit, and as a replacement to the mpz_class pow2(mpz_class exp) routine he contributed in Lucas-Lehmer_test#C++ (Which is probably painfully slow).

NevilleDNZ 06:11, 19 February 2008 (MST)

OK, but for this task, all that is required is intint and realint right? --Mwn3d 06:19, 19 February 2008 (MST)

Yes. NevilleDNZ 06:22, 19 February 2008 (MST)

It should be specified also the return type; even for intint it makes sense to return a real value, since if the exponent is negative, it is what we get mathemtically. Should we return an integer instead? (This means: if the exp is less than 0, the result is 0) --ShinTakezou 01:07, 8 December 2008 (UTC)

AWK

The awk solution is pretty weak: It does not handle fractional exponents. It looks like there is a log function for awk, so I reckon it is possible to create a fully working solution, but has been many years since I last looked at how to do this, so I need to do some revision on mathematics. I am working on a solution, but if someone already has a working algorithm then please paste it here as pseudocode, and I will try and translate it into awk. Markhobley 11:44, 7 September 2011 (UTC)

For example, Real constants and functions#bc uses e(l(2) * -3.4) to calculate 2 to the power of -3.4. This formula requires a >= 0, unless you can use complex numbers. --Kernigh 18:00, 7 September 2011 (UTC)
The exponent operator is causing confusion. I am under the impression that some versions of awk do not have this. Looking at various documentation on the internet, the caret operator is not on the list of operators. However, some documents state that POSIX lists the caret, but that doesn't mean anything because that could be a retrofit. Did System 5 awk supported the caret as an exponent operator? I only have it listed as a regular expression anchor. I was hoping to come up with a formula that does not use the exponent operator altogether. Markhobley 22:34, 7 September 2011 (UTC)