|
-
Feb 27th, 2010, 11:18 PM
#1
Thread Starter
Fanatic Member
Cube Root Error
Much to my disappointment I recently discovered that VB can not calculate the cube root (or any odd root) of a negative number even though it is a real answer.
For instance if you try
You should get -1 because -1*-1*-1 = -1. But no, VB will return NaN, not a number.
Anyways, my problem is that I'm making a graph program and the user needs to be allowed to enter any formula they want and have it evaluated so the program can graph it. But if the user enters anything with x^(1/3) or like it, it will fail.
So I was wondering if anyone knows of a way around this problem, such as an extension or patch or something that will fix the issue in Visual Basic. I haven't tried VB 2010 but does anyone know if they have they fixed it yet in that version?
Also I can't just use Math.Abs because like I mentioned, the user could enter anything, so if they put something like this:
(x - 250)^(1/3) + (x)^(1/x)
It would be way to complex to evaluate everything in the parenthesis, check for the negatives that are being squared/rooted, take the absolute value, then finish the square, and then restore the sign.
If there was an easier way to evaluate expressions in VB then maybe I could do something with parsing but as of now my method is by compiling the formula (string) the user entires as VB code and letting it solve itself by replacing x with the number I need for the coordinate.
Last edited by Vectris; Feb 27th, 2010 at 11:37 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|