Re: power(0,0)

new topic     » goto parent     » topic index » view thread      » older message » newer message
petelomax said...

After reviewing http://rosettacode.org/wiki/Zero_to_the_zero_power I have changed Phix to yield 1.

Does anyone here have any strong opinions on the matter?

Approach the Limit

Solve baseexponent when base is zero:

 
 
? power( 0.1, 0 ) 
--> 1 
 
? power(0.000000000000000000000000000000000000000000000000000000000000000000000000001,0) 
--> 1 
 
 

As the base approaches 0 zero the limit is 1 one. As a result some say 00 = 1 . The same people who taught me that the earth was flat--see history of Christopher Columbus--taught me 00= 1 .

At the Limit

The power function is using logarithms to get its result:

 
include std/math.e 
 
atom base, exponent 
 
-- trial run 
 
{base,exponent} = { 2, 3 } 
? power( 10, exponent * log10( base ) ) 
--> 8 
 
-- test the special case 
 
{base,exponent} = { 0, 0 } 
? power( 10, exponent * log10( base ) ) 
--> error 
 
-- in function log10() may only take log of a positive number 

At the limit we have an undefined case.

Pragmatic Answer

Stick with a crash and error message to give the safest result.

Stick with a crash and error message to give what openEuphoria does.

Stick with a crash and error message to give what my sliderule tells me.

If I want a result 00 = 1 then I will program it myself.

_tom

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu