Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Operator ^ cannot be applied to double..?

Thread view: 
UKP - 26 Sep 2007 09:18 GMT
Basically, the calculation without log is -

x / [ 1-1/(1+x)^n]

So, when you take log, you get logx - log(1-(1/(1+x)^n))

But, when I'm doing this same in Java, I'm getting this error
"Operator ^ cannot be applied to double.." How come  o.0

public static double f(double x) {

       return Math.log(x)-Math.log(1-(1/(1+x)^n));

   }
Ulrich Eckhardt - 26 Sep 2007 09:28 GMT
> I'm getting this error
> "Operator ^ cannot be applied to double.." How come  o.0

That operator does simply not do what you think it does. I guess you rather
want a pow() or power() function (not sure what it's called in Java). Both
should be explained in your Java book.

Uli

Signature

Sator Laser GmbH
Geschäftsführer: Ronald Boers, Amtsgericht Hamburg HR B62 932

UKP - 26 Sep 2007 09:35 GMT
^^

This should be working -

double y = Math.pow(1+x,120);

       return Math.log(x)-Math.log(1-(1/y));
Roedy Green - 26 Sep 2007 12:44 GMT
>x / [ 1-1/(1+x)^n]
>
>So, when you take log, you get logx - log(1-(1/(1+x)^n))
>
>But, when I'm doing this same in Java, I'm getting this error
>"Operator ^ cannot be applied to double.." How come  o.0

because ^ in Java means xor, not exponentiation.  Java does not have
an exponentiation operator. All it has is Math.pow and Math.exp.

See http://mindprod.com/jgloss/xor.html
http://mindprod.com/jgloss/power.html
http://mindprod.com/jgloss/exp.html
http://mindprod.com/jgloss/exponentiation.html
http://mindprod.com/jgloss/logarithms.html

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.