Java中的power运算符? [英] The power operator in Java?

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

问题描述

当我运行以下Visual Basic代码时:

When I run the following Visual Basic code :

Dim b As Double
b = (2 ^ 16 - 1) * Math.Sqrt(Math.Sqrt((a / (2 ^ 8 - 1))))

(假设 a 是一个双倍,其值为15.0)

我得到的结果 b 约为32,275。

(Assuming a is a double whose value is 15.0)
The result I get for b is about 32,275.

但是当我运行以下Java代码时,它应该与上面的代码相同:

But when I run the following Java code, which is supposed to do the same as above:

double b;
b = (2 ^ 16 - 1) * Math.sqrt(Math.sqrt((a / (2 ^ 8 - 1))));

再次 a 为15,我得到一个非常不同的结果:大约17。

Again with a being 15, I get a much different result: about 17.

两者都在解决这个等式:

Both are solving this equation:

为什么会这样?对于我正在处理的内容,Visual Basic会产生我正在寻找的结果。

Why is this so? For what I'm working on, the Visual Basic yields result I'm looking for.

推荐答案

^ 是java中的 XOR运算符 。在Visual Basic中使用 Math.pow(2,8) 2 ^ 8

^ is XOR operator in java. Use Math.pow(2,8) which is 2 ^ 8 in Visual Basic.

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

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