RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 3740 | Replies: 6
Reply
Join Date: Jun 2005
Posts: 14
Reputation: rpratt is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
rpratt rpratt is offline Offline
Newbie Poster

Issues using Math class

  #1  
Jul 26th, 2005
Hi,
Has anyone had the following problem?

When I run the following code (just using Notepad and my DOS prompt):

public class MathFunctionsApp2
{
public static void main(String[] args)
{

int b = -50;
double x = 25.0;
double y = 3.0;
double z = 4.0;


System.out.println("cbrt(x) = "+ Math.cbrt(x));

System.out.println("hypot(y,z) = "+ Math.hypot(y,z));

System.out.println("log10(y) = "+ Math.log10(y));

System.out.println("signum(b) = "+ Math.signum(b));

}

}

It won't compile - it doesn't like SOME of the mathematical functions provided by the Math Class. (See error note below)

MathFunctionsApp2.java:13: cannot resolve symbol
symbol : method cbrt (double)
location: class java.lang.Math
System.out.println("cbrt(x) = "+ Math.cbrt(x));
^
MathFunctionsApp2.java:15: cannot resolve symbol
symbol : method hypot (double,double)
location: class java.lang.Math
System.out.println("hypot(y,z) = "+ Math.hypot(y,z));
^
MathFunctionsApp2.java:17: cannot resolve symbol
symbol : method log10 (double)
location: class java.lang.Math
System.out.println("log10(y) = "+ Math.log10(y));
^
MathFunctionsApp2.java:19: cannot resolve symbol
symbol : method signum (int)
location: class java.lang.Math
System.out.println("signum(b) = "+ Math.signum(b));
^
4 errors


However, it will accept some of the other Mathematical functions, such as sqrt, max, exp, etc. (I just didn't include them here - but they do work!)

Oh, and I also CAN get it to run if I just use TextPad.

Would love any advice I can get!
Thanks.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

Re: Issues using Math class

  #2  
Jul 26th, 2005
Well, none of those are functions in the math class.
You can find a list here:
http://java.sun.com/j2se/1.4.2/docs/...lang/Math.html

I can help you with a few of those:
To get the cube root:

Math.pow(base,3);

To get log base 10 of X:

int answer = Math.log(x)/Math.log(10);

To get hypotenuse a little more work is needed:

Math.sqr((Math.pow(a,2)+Math.pow(b,2));

I think that will work, not sure.

I don't know what you want on your last thing though.
Reply With Quote  
Join Date: Jun 2005
Posts: 14
Reputation: rpratt is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
rpratt rpratt is offline Offline
Newbie Poster

Re: Issues using Math class

  #3  
Jul 27th, 2005
Originally Posted by server_crash
Well, none of those are functions in the math class.
You can find a list here:
http://java.sun.com/j2se/1.4.2/docs/...lang/Math.html

I can help you with a few of those:
To get the cube root:

Math.pow(base,3);

To get log base 10 of X:

int answer = Math.log(x)/Math.log(10);

To get hypotenuse a little more work is needed:

Math.sqr((Math.pow(a,2)+Math.pow(b,2));

I think that will work, not sure.

I don't know what you want on your last thing though.
But here's the weird thing - it DOES work with TextPad. Also - the way that I found these was from a "Java for Dummies" book. Doesn't it seem strange that it would work with TextPad?

Thanks for the website though - very useful!

PS The signum returns the sign of the argument. I have no idea why this is useful. Just was trying out what the book suggested...
Reply With Quote  
Join Date: Jun 2005
Posts: 14
Reputation: rpratt is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
rpratt rpratt is offline Offline
Newbie Poster

Re: Issues using Math class

  #4  
Jul 27th, 2005
Aha!! I figured it out!!

The math functions I was looking at are new to Java's version 1.5.0_04!!

For the very latest list:

java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html

And.... it turns out that my path was still pointing to the old version of Java (1.4 etc), NOT 1.5.0!

Hope someone can make good use of this!
Reply With Quote  
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

Re: Issues using Math class

  #5  
Jul 27th, 2005
I see what it is. TextPad must come with extra classes that make things easier. A lot of times you will get things like this. I know normally you'll find an easier class to help out with reading and writing data.

To get the sine of a number in the normal methods:

Math.sin(x);


You won't be able to use those methods you have unless TextPad actually came with them, or you download them. I would suggest using the normal classes though.
Reply With Quote  
Join Date: Jun 2005
Posts: 14
Reputation: rpratt is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
rpratt rpratt is offline Offline
Newbie Poster

Re: Issues using Math class

  #6  
Jul 27th, 2005
I think you're right about TextPad. But, also, check out my above comment about the new version of Java - I think that's why the book was recommending these functions.

Thanks again for all your help!
Reply With Quote  
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

Re: Issues using Math class

  #7  
Jul 27th, 2005
Sorry, we must have posted at the same time because I did'nt see that. But that's cool, I never checked 1.5's new Math features. It's good they added a few of those like log10.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:12 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC