开发者

Java math conversion

I have this code in C++

float res开发者_JAVA技巧ult = -log(result)/0.5231-1.0;

And I converted that into Java code like this

float result = (float) (-Math.log(result)/0.5231-1.0);

Is this correct way to convert the c++ code?


Well, the first C++ statement is illegal. You are defining result, and while initializing you use result.

But yes, the Java code does the same as the C++ code, if we ignore the irrelevant errors.


That is not really a question, but yes, the code you've written in Java does the same as your C++ code.

I wouldn't suggest converting big pieces of code from C++ to java.


Yes, this is correct. But you need to declare "result" above in code.

float result = ... ;    
result = (float) (-Math.log(result)/0.5231-1.0);

BTW there are many java libs for math purposes. E.g. http://commons.apache.org/math/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜