Once again encountered the hidden transformation of the + = operation.

Source: Internet
Author: User
Tags diff

To hide the transformation problem, for a simple example, everyone already knows:

Short i=1,j=1;

Short k = i+j;//Compilation error, requires manual transformation.

But i++ is possible. This involves the problem of hiding the transformation.


Today optimization code, the original double with a float, there is no modification, it can correctly compile:

float sum = 0;
float[] location = Point.getlocation ();
if (location = = NULL | | mdescriptor = = NULL) return float.max_value;

for (int i = 0; i < mdescriptor.length; i++) {
Double diff = mdescriptor[i]-location[i];
sum + = Diff*diff;
}
return sum;

The product of the diff of Double can be directly to the sum of float for + = operation.

Asked for a long time, finally found the http://stackoverflow.com/questions/8710619/java-operator.


Of course, the diff of this code is finally changed to float, only in the middle of the process of modification to find this phenomenon.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.