This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

pls. help division by zero

 
deekasha gunwant
Ranch Hand
Posts: 396
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

it's clearly mentioned in jaworaski (chap 3)that

an integer by zero an ArithmeticException.
positive floating-point value by zero POSITIVE_INFINITY.
negative floating point value by zero NEGATIVE_INFINITY.
Note that when the sign of zero is negative, such as -0, the sign of the result is reversed.

so i write a small program but it is not behaving expectedly
class DivisionTest
{
public static void main(String m[])
{
int i =10;
float j = 10.0f;
System.out.println(j/0);
System.out.println(-j/0);
System.out.println(-j/(-0));
}
}
according to my understanding the o/p should be
infinity
-infinity
infinity
but the out put is
DivisionTest.java:7: Arithmetic exception.
System.out.println(j/0);
^
DivisionTest.java:8: Arithmetic exception.
System.out.println(-j/0);
^
DivisionTest.java:9: Arithmetic exception.
System.out.println(-j/(-0));
^
3 errors

can anybody pls. throw some light why this is happening?
i'm using WinNT /jdk1.2.1
thanx in advance
deekasha
 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm.. that's interesting.
I am running JDK 1.2.2 and it prints correct results for me ie.,
Infinity
-Infinity
-Infinity
May be you can run a quick search on Sun's bug parade to see if this inconsistency was reported in JDK 1.2.1 and fixed later.
Ajith
 
Surya B
Ranch Hand
Posts: 98
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I think its got something to do with the java compiler,if i use
JDK 1.2.2 then it compiles fine,but if i use JDK1.1.6 then it gives the compile time errors.I think the same is the problem with
JDK1.2.1.Thanks.
Surya
[This message has been edited by Surya B (edited July 31, 2000).]
 
Helen Yu
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,there:
----------------------------------------------
an integer by zero an ArithmeticException.
positive floating-point value by zero POSITIVE_INFINITY.
negative floating point value by zero NEGATIVE_INFINITY.
Note that when the sign of zero is negative, such as -0, the sign of the result is reversed.
so i write a small program but it is not behaving expectedly
class DivisionTest
{
public static void main(String m[])
{
int i =10;
float j = 10.0f;
System.out.println(j/0);
System.out.println(-j/0);
System.out.println(-j/(-0));
}
}
-----------------------------------------
I tried my 1.2.2 compiler, the result is same as above, but when you say" if sign of zero is negative, the sign of result is reserve??? The last two statements print all the same " -Infinity", why? please advise.
Thanks
 
Netla Reddy
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using JDK 1.2 & WIN NT and it prints correct results for me ie.,
Infinity
-Infinity
-Infinity
Thanks
[This message has been edited by Netla Reddy (edited July 31, 2000).]
 
thomas
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer Helen's qn:
The primitive integer types do not differentiate between +0 and
-0. So when the integral operand is promoted to a floating-point type, it simply becomes 0.0.
10.0/0 will give Infinity
10.0/-0 will also give Infinity
But the floating-point types differentiate between +0.0 and -0.0.
10.0/0.0 will give Infinity
10.0/-0.0 will give -Infinity
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic