是否可以在Java中创建指数运算符? [英] Is it possible to create an exponent operator in java?

查看:103
本文介绍了是否可以在Java中创建指数运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如主题所说,我真的很想知道是否有可能创建一个指数运算符作为Java库的补充,该指数运算符将由"^"表示,并且功能类似于任何其他运算符,例如+,-,/或*.我对Java相对较新(尽管对编程不是新手),并且我还记得Microsoft的VB(尽管不是很出色的语言)确实使用了指数运算符.

但是,如果这不可能,那么有人可以向我解释如何在Android科学计算器中实现Math.pow()类吗?该程序基于本教程中找到的程序, Android开发简介:TouchCalculator [^ ] ,尽管我已经对代码进行了很多扩展.但是,我很难在程序中调整此操作.

如果我将其改编为一种更简单,不太理想的计算器格式,那么我将没有问题.但是,在保持程序原始格式的同时执行此操作是非常麻烦的任务.

非常感谢所有帮助!

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!

推荐答案

在VB中,"^"运算符不是指数,而是幂运算符,N ^ p表示N p ,指数"表示e x ,在VB中为e ^ x:
http://msdn.microsoft.com/en-us/library/zh100ckf%28v = vs.100%29.aspx [ ^ ].

指数"是一元函数,并且没有任何语言的一元运算符.是的,"^"是一个二进制中缀运算符,介于要加N的数字和指数p之间(如上所述).

因此,这个问题已经不是很正确,或者至少还不清楚.

那么,Java有什么问题呢?在Java中,"^"表示XOR运算符,您需要的函数为Math.pow(double, double),指数函数为Math.exp(double):
http://en.wikipedia.org/wiki/Exclusive-or [ http://docs.oracle.com/javase/6/docs/api/java/lang/Math.html [ ^ ].

现在,在通常的方法中,运算符和函数在您用于实现计算器的语言中的外观与它在计算器中的外观无关.在计算器中……他们将看您如何设计它;实现语言的语法不能阻止它;至少是开发人员知道什么是编程.我什至不了解这怎么可能是一个问题,但是几乎可以肯定您可以做到.

—SA
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:
http://msdn.microsoft.com/en-us/library/zh100ckf%28v=vs.100%29.aspx[^].

"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):
http://en.wikipedia.org/wiki/Exclusive-or[^],
http://docs.oracle.com/javase/6/docs/api/java/lang/Math.html[^].

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.

—SA


这篇关于是否可以在Java中创建指数运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆