About a in Java! = True interpretation of a value (excerpt)

Source: Internet
Author: User
About a in Java! = The A value is interpreted as true.

In Java spec, the primitive type is implemented in a certain defined way. The Floating-types are implemented in IEEE-754 standard.
Ref from Java SPEC:
The IEEE 754 standard instances des not only positive and negative sign-magn1_numbers, but also positive and negative zeros, positive and negative Infinities , And a special Not-a-number Value (hereafter abbreviated as "Nan"). The Nan value is used to represent the result of certain invalid operations such as dividing zero by zero.
so, in this case, Java specified that! = A is true if the variable is Nan. so does the case I present yesterday (A = B) If either A or B is Nan.
now I wil give you a example show it:
.........
double A = 0;
double B = 0;
A = A/B;
if (! = A) system. Out. println ("OK,! = A is true! ");
If (A = B) system. out. println ("........ ");

But I think the problem is a little tricky, if you have not yet read something from the Java Spec or something other, you will not know that. but when the problem been proposed to us, We shoshould think about the problem in a logical way, but not the way coding it to see if a = 0, and then! = A is false. What I want to see is not the result of this, but the thinking way of the job seeker.

The same is true in. NET 2.0.

Module test
Sub main ()
Dim A as double = 0
Dim B as double = 0
A = A/B
Console. writeline ("A = {0}",)
Console. writeline ("A <> A = {0}", a <>)
Console. writeline ("A = {0}", a =)
Console. writeline ("A <B = {0}", a <B)
Console. writeline ("A> B = {0}", A> B)
Console. writeline ("a = B = {0}", A = B)
End sub
End Module

Result:
A = non-numeric
A <> A = true
A = false
A <B = false
A> B = false
A = B = false

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.