Click here to Skip to main content
15,070,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
As the subject states, I would really like to know if it is possible to create an exponential operator as a supplement to Java's libraries, which would be represented by "^" and function like any other operator, such as +, -, /, or *. I'm relatively new to Java (although not new to programming), and I remember that Microsoft's VB (although not a very great language otherwise) did utilize an exponential operator.

If this is not possible, however, could someone please explain to me how I could implement the Math.pow() class in an Android scientific calculator? The program is based upon the one found in this tutorial, Introduction to Android development : TouchCalculator[^], although I've expanded upon the code very much. I am, however, having much difficulty at adapting this operation for the program.

If I were adapting it for a much simpler, less desirable calculator format, I would have no problem. Implementing this operation while maintaining the clean format of the program, however, is (to me) a very troublesome task.

All aid is greatly appreciated!

1 solution

In VB, the '^' operator is not exponent, but a power operator, N ^ p means Np, and "exponent" means ex, in VB it would be e ^ x:[^].

"Exponent" is a unary function, and there is no a unary operator for it in any language. And '^', yes, is a binary infix operator, between number to be N powered and the exponent p (as denoted above).

So, the question is already not quite correct, or at least not clear.

So, what's the problem with Java? In Java, '^' means XOR operator, and the function you need is Math.pow(double, double), and the exponential function is Math.exp(double):[^],[^].

Now, how operators and functions look in the language you use for implementation of a calculator, has nothing to do with how it looks in a calculator, in a usual approach. In a calculator… they will look how you design it; and the syntax of the implementation language cannot prevent it; at least is a developer has an idea what programming is. I don't even understand how can it be a problem, but pretty much sure you can do it.

Niklas L 13-Jun-12 4:37am
Have a 5
Sergey Alexandrovich Kryukov 13-Jun-12 12:22pm
Thank you, Niklas.
VJ Reddy 13-Jun-12 13:10pm
Good answer. 5!
Sergey Alexandrovich Kryukov 13-Jun-12 18:22pm
Thank you, VJ.
Zack Strickland 13-Jun-12 13:16pm
I apologize for the very, very stupid question =/ I figured it out on my own after looking at it some more and felt very foolish for asking.
Sergey Alexandrovich Kryukov 13-Jun-12 18:23pm
No need to apologize -- we all make mistakes; and sometimes its good to say something aloud to understand it better.
If you agree that my post makes sense, will you formally accept the answer (green button)? -- thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900