# The Same Doubt Again

Ranch Hand
Posts: 579

Hello Javaranchers,
In This Forum, Many Times I Myself And Other Persons Have As
Asked Questions Relating To NaN Many Times But Some People Said
Some Of The Properties And Said That To Know Only This Much Is Sufficient
But I Am Getting Questions Continuously Relating To NaN.Pls Tel Me Some Other Properties Of It For Exam Purpose.I Don't Want To Revise The Whole Documentation Related To It

Also
###################################################
Question 30

When executed the following line of code will print
System.out.println(-1 * Double.NEGATIVE_INFINITY);

A) -Infinity
B) Infinity
C) NaN
D) -NaN
Why The Output Is (B)

Thanx

Steve Morrow
Ranch Hand
Posts: 657
When executed the following line of code will print
System.out.println(-1 * Double.NEGATIVE_INFINITY);

A) -Infinity
B) Infinity
C) NaN
D) -NaN
Why The Output Is (B)
Instead of having us guess at what you're confused about, tell us why you are confused by this answer. What is it about multiplying two negative numbers leads you to believe you'd get something other than a positive number? What in the specification have you seen that leads you to believe that multiplying infinity by a non-zero finite number would produce something other than an infinity of the appropriate sign?

Perhaps by telling us what you're confused about, we can provide you with a more direct answer to help ease your apparent frustration.

Ranch Hand
Posts: 579
Hello Mr.Steve Just Mind Ur Language................
I Was Having This Doubt So I Asked...........I Was Confused Why
Can't It Give "NaN" Itself Because NaN is Always Having
Some Different Properties like NaN Is Not Equal To Anything Including Itself.I Am Requesting You To Mind Your Way Of Answering...................
Because It Has Always Been Your Way.........Just Mend.
Anyone Of Us Is Not Perfect.Please Be Some More Polite In Answering.
#########################################
[ September 22, 2005: Message edited by: agrah upadhyay ]

Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
The underlying specification for float and double numbers in Java is a called commonly called IEEE 754. It sets the rules for certain non-numeric results and how they will be described.

This article is useful for a full technical description. If you want to know the rationale for the answer above, you will probably have to do more review than you seem willing to do.

Steve Morrow
Ranch Hand
Posts: 657
Just Mind Ur Language................
I Was Having This Doubt So I Asked...........I Was Confused Why
Can't It Give "NaN" Itself Because NaN is Always Having
Some Different Properties like NaN Is Not Equal To Anything Including Itself.I Am Requesting You To Mind Your Way Of Answering...................
Because It Has Always Been Your Way.........Just Mend.
Anyone Of Us Is Not Perfect.Please Be Some More Polite In Answering.

I don't see anything rude in my initial response. I asked you to provide more information as to what you're confused about so we could better answer your question. If that's all it takes for you to get insulted and indignant, I suggest you hire someone who will coddle and spoon-feed you everything you want to know.

I was genuinely interested in what confused you about that problem. At your request, however, I'll be happy to refrain from trying to assist you any further. Good luck.

Steve Morrow
Ranch Hand
Posts: 657
P.S. Mr. Agrah, you may also benefit by reading the following: http://www.catb.org/~esr/faqs/smart-questions.html#keepcool

A Kumar
Ranch Hand
Posts: 980
Hi agrah,

I believe Steve only asked you the cause for your confusion...and he didnt chide you about not knowing the answer...It was plain ...

If you had been expecting some other answer...which seems to be what he is intending..i will believe he had put it rightly... There was no offence meant ...

Regards

Ranch Hand
Posts: 579
ME: I am striking the full of this post. It was rude, snide, and in my opinion lacked the very civility it requested from another subscriber.

[ September 22, 2005: Message edited by: agrah upadhyay ]
[ September 23, 2005: Message edited by: Michael Ernest ]

Srinivasa Raghavan
Ranch Hand
Posts: 1228
Check it out i googled to get this url.

Steve Morrow
Ranch Hand
Posts: 657
I believe Steve only asked you the cause for your confusion...and he didnt chide you about not knowing the answer...It was plain ...

If you had been expecting some other answer...which seems to be what he is intending..i will believe he had put it rightly... There was no offence meant ...
You are correct, and thank you.

Ranch Hand
Posts: 579
Hello A Kumar
Yaa This Time May Be He Is Right But His And Only His Way Of Answering Has
Offended Me Many Times That's Why I Quoted So.But If Many Of
You Think That He Is Right-He May Be.

Thanx

Steve Morrow
Ranch Hand
Posts: 657
Yaa This Time May Be He Is Right But His And Only His Way Of Answering Has Offended Me Many Times That's Why I Quoted So.
I would suggest you're taking things far too personally. I don't remember ever having answered you before, so I have no idea about this history of repeated offense of which you speak. I intended no offense; similarly, you should consider toning down the sensitivity.

Good luck.

Ranch Hand
Posts: 579
I Think I Should Stop This Discussion Here cause You Are Making It As A Issue Like Posting A Kumar's View.I Must Stop Otherwise You Will Go Enen To Hague!
Thanks For Suggestion But Sorry You Are The Only Person Who Suggested Me But I Wantb Suggest You Cause You Definitely Won't Listen.

Steve Morrow
Ranch Hand
Posts: 657
I Think I Should Stop This Discussion Here cause You Are Making It As A Issue Like Posting A Kumar's View.I Must Stop Otherwise You Will Go Enen To Hague!
Thanks For Suggestion But Sorry You Are The Only Person Who Suggested Me But I Wantb Suggest You Cause You Definitely Won't Listen.

What does "Go Enen To Hague" mean?

And did you happen to read Michael Ernest's post?
[ September 22, 2005: Message edited by: Steve Morrow ]

Ranch Hand
Posts: 579
Yaa I Read Mr. Ernest's Post.He Is Suggesting Me To Have A Wider Review Of Some Topics..........And I Am Doing The Same.
And In My Earlier Post In'Enen to Hague' Should Be 'Even To Hague'.
Thanx.

Steve Morrow
Ranch Hand
Posts: 657
Yaa I Read Mr. Ernest's Post.He Is Suggesting Me To Have A Wider Review Of Some Topics..........And I Am Doing The Same.
Okay, so he asked you to do more research. I asked you what you found confusing about the research you had done. I don't understand what you found so offensive, but it doesn't really matter at this point.

And In My Earlier Post In'Enen to Hague' Should Be 'Even To Hague'.
Thanx.
Unfortunately, that doesn't make the meaning any more clear to me.

Ranch Hand
Posts: 579
With Regards Again Mr.Steve
But In My Earlier Posts When I Asked The Question Related To NaN One Rancher Asked Me To Just Know 3 Points And He Also Quoted Them Too.So I Was Satisfied With Them And Thougt That I won't Face Problem Anymore But Really I Was Not Able To Guess The Answer of Above Question.So I Raised The Question.

Thanx

Steve Morrow
Ranch Hand
Posts: 657
So I Raised The Question.
So, do you understand it now, or are you still confused? If you are still confused, please explain what you are confused about (remember that when you multiply two negative numbers, the result is positive, and when you multiply any non-zero finite number by infinity, the answer is infinity).

Here I am going back on my word to not assist; I hope you guys respect me in the morning...
[ September 22, 2005: Message edited by: Steve Morrow ]

anand phulwani
Ranch Hand
Posts: 242
Dear Agrah and Steve,

First of all i would like to request that everyone over here is to help all of us ,so i think we can request Mr Barry to have another Forum for fighting which Mr Barry would like to transfer it to,and when the conversation becomes soothing it will be retaken in Certification forum ,anyways Agrah i want to suggest you that please see before you tpe anything Mr Steve is one who has posted 440 something posts so he deserves a respect and before shouting at him one should think thrice or more than it,and see to it before starting the fight you can just ask that "Mr Steve the language you wrote seems to be rude,i would appreciate if you edit your post",but i would also want to say to Mr Steve that i think we are here to solve problems not create problems,Woudn't it be nice if you just could give a full length explaination if you wished otherwise there is always someone else to do it,So i think we are Ranchers and i think we are like a family,So i apologise to both of you on behalf of both of you,and apologise for myself if i have done something wrong ,but now i think you both can be friends isn't it Mr Steve and Mr Agrah???

Thanks
"Proud To Say I Am A Rancher"
Anand

anand phulwani
Ranch Hand
Posts: 242
Dear Ranchers,

On my 101 post and completing 100 posts i would like to say
I AM PROUD TO BE A RANCHER!!!

Thanks,
With Regds,
Anand

Steve Morrow
Ranch Hand
Posts: 657
Woudn't it be nice if you just could give a full length explaination if you wished otherwise there is always someone else to do it
I hear what you're saying and I appreciate the input. My full length explanation would be, "The answer is (B) because multiplying two negatives make a positive and multiplying infinity by a non-zero finite number results in infinity." Honestly, I don't know how to be more complete than that, and that's pretty much what I covered in my first post.

Someone can ask me to edit my post for rudeness, but for the life of me, I don't see what's rude about it (as opposed to the following response that told me to "mind my language" and not to answer at all). When I've asked questions and been asked to clarify in a similar manner, I've not considered it rude at all; rather I worked to provide the information that those who were trying to help me were asking for.

I asked the OP about his source of confusion in order to help. If he found something particularly confusing about the documentation or mathematics in general, I could then give a more detailed, "full-length" explanation, specifically tailored to addressing the points s/he found confusing. As it is, he asked a general question about a topic that's been discussed at length here and elsewhere throughout the internet, so I asked for clarification. If *that's* offensive, I'm afraid all my posts are going to be that way. It's not my intention at all to create arguments here, but if asking for clarification is "rude" or "arrogant", I'm afraid the proposed atmosphere might be a little too "friendly" to be useful.

I enjoy helping others, and expect that one of the moderators (bartenders, sheriffs, etc.) will address my demeanor here with me personally and privately if I happen to violate the expected norms on this forum. If my post was read as offensive, I can guarantee it was misinterpreted, as that was not my intention.

Thanks again for the suggestions. Please don't apologize on my behalf, and there's nothing for you to be sorry for, either. Either way, I imagine this topic will be closed soon (as it's traveled far enough off-topic and dragged on quite long enough), so I hope to see you around...

Cheers!
[ September 22, 2005: Message edited by: Steve Morrow ]

marc weber
Sheriff
Posts: 11343
I work for a U.S. company that outsources to other countries. Based on what some of our trainers have reported after conducting courses overseas, I'm inclined to think that there might be a cultural misunderstanding here.

In some cultures, if a student asks a question (which they might be less inclined to do in the first place, compared to their American counterpart), they expect a "direct" answer. Responding with rhetorical questions designed to "lead" the student is often considered evasive and is not recognized as helpful. And responding with questions about the student's confusion might even be considered insulting -- as if to mock or belittle them. Yet in American culture, the approach of answering a question with a question -- and openly examining the student's source of confusion -- is generally considered a "good" teaching approach.

I don't know the best way to address this. But I do think we all need to be aware of these things, and somehow make allowances for these differences. Because after all, "there are three types of people in the world..."

Steve Morrow
Ranch Hand
Posts: 657
I'm inclined to think that there might be a cultural misunderstanding here.
I'm inclined to agree with you.

I don't know the best way to address this. But I do think we all need to be aware of these things, and somehow make allowances for these differences.
I don't know the best way to address it either, but I think the article by Eric Raymond (particularly the cited passage) is apropos. Of course, JavaRanch is warmer and fuzzier place that some of the "Other Forums".

That said, a discussion on whose shoulders the responsibility for personal offense lies takes a lengthy tangent from the typical SCJP Forum subject matter...

marc weber
Sheriff
Posts: 11343
Here's what I had in my own notes regarding NaN...

NaN is non-ordinal, so relational comparisons involving NaN always result in false. The only exception is NaN != NaN, which returns true. Wrapper methods Float.isNaN(float) and Double.isNaN(double) can be used to test for NaN. Alternatively, a float or double is NaN if it is not equal to itself (e.g., x != x).

Further...
• float or double division by zero results in NaN (rather than an ArithmeticException).
• Math.round(Float.NaN) results in an int zero, and Math.round(Double.NaN) results in a long zero.
• String literals "NaN" and "Infinity" are acceptable for Float and Double constructors.
•
Steve Morrow
Ranch Hand
Posts: 657
Though it may seem silly to point out, it might be worth noting:

Bert Bates
author
Sheriff
Posts: 8900
5
A couple of points:

1st - even though it doesn't say it explictly in the SCJP 5 objectives, questions about NaN disappeared with questions about the math class, so if you're studying for SCJP 5, you can skip the whole topic of NaN and positive and negative infinities

2nd - I think Marc raises a good point about different cultures. I know that many of the bartenders (myself included), tend to try to approach questions as learning exercises... in other words we prefer not to answer technical questions directly, but instead to help provide a tips or clues as to how to look at problems. This is especially true when we think that someone just wants us to do their homework for them :roll: , which obviously isn't the case in this thread. So i hope ranchers won't be offended by this approach, I think it's very common here at the ranch, and I think it is well aligned with the whole 'be nice' approach.

hth,

Bert

A Kumar
Ranch Hand
Posts: 980
Hi,

Regarding marcs post..

float or double division by zero results in NaN (rather than an ArithmeticException).

Its true that int division by zero gives you Arithmetic exception...

but

float or double division by zero ...

System.out.println(1.0/0.0 ); //Gives Infinity
System.out.println(0.0/0.0 ); //Gives NaN
System.out.println(Float.MAX_VALUE/0.0 ); //Gives Infinity

Regards

Akshay Kiran
Ranch Hand
Posts: 220
well, if you're taking the scjp, you can't go on saying "i don't want to look at the API docs" - makes no sense.

java.lang.Double
public static final double MAX_VALUE 1.7976931348623157E308d
public static final double MIN_VALUE 4.9E-324d
public static final double NaN 0d/0d
public static final double NEGATIVE_INFINITY -1d/0d
public static final double POSITIVE_INFINITY 1d/0d

java.lang.Float
public static final float MAX_VALUE 3.4028234663852886E38f
public static final float MIN_VALUE 1.401298464324817E-45f
public static final float NaN 0f/0f
public static final float NEGATIVE_INFINITY -1f/0f
public static final float POSITIVE_INFINITY 1f/0f

java.lang.Integer
public static final int MAX_VALUE 2147483647
public static final int MIN_VALUE -2147483648

java.lang.Long
public static final long MAX_VALUE 9223372036854775807l
public static final long MIN_VALUE -9223372036854775808l

All these constants have internal bit representations, therefore any comparison using the equals method will obviously return true though this is mathematically incorrect (I'm talking about the nans and infinities).
If you look into the details of these constants in the API you will see why (Double.NAN).equals(Float.NAN) must return false.

However,
public boolean equals(Object obj)
Compares this object against the specified object. The result is true if and only if the argument is not null and is a Double object that represents a double that has the same value as the double represented by this object. For this purpose, two double values are considered to be the same if and only if the method doubleToLongBits(double) returns the identical long value when applied to each.
Note that in most cases, for two instances of class Double, d1 and d2, the value of d1.equals(d2) is true if and only if

d1.doubleValue() == d2.doubleValue()
also has the value true. However, there are two exceptions:

If d1 and d2 both represent Double.NaN, then the equals method returns true, even though Double.NaN==Double.NaN has the value false.
If d1 represents +0.0 while d2 represents -0.0, or vice versa, the equal test has the value false, even though +0.0==-0.0 has the value true.
This definition allows hash tables to operate properly.

And secondly, I think this discussion has oft strayed because of incompatible ego states anyway I firmly believe that one has to set aside one's ego while one is learning

anand phulwani
Ranch Hand
Posts: 242
Dear Mr Steve,

I totally agree with you that awnsering a question with a question ,clues is the best thing out there,but regarding indian culture as Agrah and me both are indians ,this thing is rather changed to spoon-feeding over here because here question are awnsered with awnsers and not question,i want to say that neither american teaching is wrong nor say that indian teaching is wrong,but it differs from culture to culture,so i think its a big misiterpretation what Mr Steve wrote,so i think we dont need to worry,
and we can just enjoy as we are.thats all i have for now.

Thanks,
With Regds,
Anand

Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
A message from your local Sheriff:

We'll have a zero tolerance in this and other forums for hostile and confrontational messages. Those of you who need to stir up some dust, take it somewhere else.

I'm going to be sitting on a plane for most of the day. You can bet I'll be getting home a little cranky. Anyone who still wants to project attitude with words then, I'll be happy to talk to you.

Steve Morrow
Ranch Hand
Posts: 657
float or double division by zero ...

@A Kumar:

I've found this chart from The Java� Programming Language to be useful...

marc weber
Sheriff
Posts: 11343
Originally posted by A Kumar:
... Its true that int division by zero gives you Arithmetic exception...
but float or double division by zero...
System.out.println(1.0/0.0 ); //Gives Infinity
System.out.println(0.0/0.0 ); //Gives NaN
System.out.println(Float.MAX_VALUE/0.0 ); //Gives Infinity
...

You are correct.

I should have said, "float or double division by zero results in +/- Infinity (rather than an ArithmeticException), except dividing zero by zero, which results in NaN."