Cube root

B

Brock

I routinely use sqrt(x) for getting a cube root in vb.net. does anyone
know of a way of getting the cube root? I tried cbrt(x) and that
didn't work.
thanks!
 
J

jch

Maybe there's built-in VB function to do this but here's how I'd do it.

dblCubeRoot = dblNumber ^ (1/3)

You can change '3' to be whatever root you're trying to get. Ex: (1/2)
would give you the square root.
 
A

Andrew Morton

AMercer said:
the cube root of positive x is
x ^ (1 / 3)

Ahem! :) The /real/ cube root of x is x^(1/3).

Console.WriteLine( -8 ^ (1 / 3)) correctly gives -2. The complex roots are,
of course, beyond my brain this early in the morning.

Andrew
 
A

AMercer

Console.WriteLine( -8 ^ (1 / 3)) correctly gives -2.

The minus sign applies to the entire expression; it needs to apply to 8.
(-8) ^ (1 / 3) is NAN.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top