1. problem with euphoria's power()

Consider the following line of code:

? power(-8, 1/3)

I get the following error:

can't raise negative number to non-integer power.

Wrong! raising any number to 1/3 gives the cubed root, and anyone with even 
a little math experience knows that all negative numbers have real cubed 
roots. Same applies with 1 / <any odd integer>.  So, what's the problem Rob?

regards,
Daryl van den Brink

new topic     » topic index » view message » categorize

2. Re: problem with euphoria's power()


new topic     » goto parent     » topic index » view message » categorize

3. Re: problem with euphoria's power()

On 5 Aug 2001, at 20:09, daryl_vdb at HOTMAIL.COM wrote:

> 
> Consider the following line of code:
> 
> ? power(-8, 1/3)
> 
> I get the following error:
> 
> can't raise negative number to non-integer power.
> 
> Wrong! raising any number to 1/3 gives the cubed root, and anyone with even 
> a little math experience knows that all negative numbers have real cubed 
> roots. Same applies with 1 / <any odd integer>.  So, what's the problem Rob?

If we had the log10 function instead of the natural logs function, we could get
any root
or power by using that function:

atom = 10E(0.3 x log(1728))
-- atom = 12

Kat

new topic     » goto parent     » topic index » view message » categorize

4. Re: problem with euphoria's power()

>If we had the log10 function instead of the natural logs function, we could 
>get any root
>or power by using that function:
>
>atom = 10E(0.3 x log(1728))
>-- atom = 12
>
>Kat

Here's some code I coppied from a math library I wrote a while ago.  It lets 
you get logarighms with any base. (10, 16 and 8 are sped up a little)

-- logarithms --

constant log10 = log(10),
        log16 = log(16),
        log8 = log(8)

global function declog(object x)
    return log(x) / log10
end function

global function hexlog(object x)
    return log(x) / log16
end function

global function octlog(object x)
    return log(x) / log8
end function

global function customlog(object x, object base)
    return log(x) / log(base)
end function


regards,
Daryl van den Brink

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu