Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8699145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:52:36+00:00 2026-06-13T01:52:36+00:00

The following statement throws java.lang.ArithmeticException: / by zero as obvious. System.out.println(0/0); because the literal

  • 0

The following statement throws java.lang.ArithmeticException: / by zero as obvious.

System.out.println(0/0);

because the literal 0 is considered to be an int literal and divide by zero is not allowed in integer arithmetic.

The following case however doesn’t throw any exception like java.lang.ArithmeticException: / by zero.

int a = 0;
double b = 6.199;
System.out.println((b/a));

It displays Infinity.

The following statement produces NaN (Not a Number) with no exception.

System.out.println(0D/0); //or 0.0/0, or 0.0/0.0 or 0/0.0 - floating point arithmetic.

In this case, both of the operands are considered to be double.


Similarly, the following statements don’t throw any exception.

double div1 = 0D/0; //or 0D/0D
double div2 = 0/0D; //or 0D/0D

System.out.printf("div1 = %s : div2 = %s%n", div1, div2);
System.out.printf("div1 == div2 : %b%n", div1 == div2);
System.out.printf("div1 == div1 : %b%n", div1 == div1);
System.out.printf("div2 == div2 : %b%n", div2 == div2);
System.out.printf("Double.NaN == Double.NaN : %b%n", Double.NaN == Double.NaN);
System.out.printf("Float.NaN == Float.NaN : %b%n", Float.NaN == Float.NaN);

They produce the following output.

div1 = NaN : div2 = NaN
div1 == div2 : false
div1 == div1 : false
div2 == div2 : false
Double.NaN == Double.NaN : false
Float.NaN == Float.NaN : false

They all return false. Why is this operation (division by zero) allowed with floating point or double precision numbers?


By the way, I can understand that floating point numbers (double precision numbers) have their values that represent positive infinity, negative infinity, not a number (NaN)…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:52:37+00:00Added an answer on June 13, 2026 at 1:52 am

    In short, that’s the way it’s specified in the IEEE-754 standard, which is what Java’s Floating-Point Operations are based on.

    Why doesn’t division by zero (or overflow, or underflow) stop the program or trigger an error? Why does a standard on numbers include "not-a-number" (NaN)?

    The 754 model encourages robust programs. It is intended not only for numerical analysts but also for spreadsheet users, database systems, or even coffee pots. The propagation rules for NaNs and infinities allow inconsequential exceptions to vanish. Similarly, gradual underflow maintains error properties over a precision’s range.

    When exceptional situations need attention, they can be examined immediately via traps or at a convenient time via status flags. Traps can be used to stop a program, but unrecoverable situations are extremely rare. Simply stopping a program is not an option for embedded systems or network agents. More often, traps log diagnostic information or substitute valid results.

    Flags offer both predictable control flow and speed. Their use requires the programmer be aware of exceptional conditions, but flag stickiness allows programmers to delay handling exceptional conditions until necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following statement: java.lang.Object.wait(Object.java:???)[Native Method] - waiting on <0x6ab0eb48> (a coldfusion.runtime.RWLock) coldfusion.runtime.RWLock.waitForLock(RWLock.java:154) What
The code in the following snippet throws java.lang.StackOverflowError . public class Main { private
Does the following statement holds for any double (Java primitive double precision IEEE-754) except
How to write following statement in c using switch statement in c int i
At runtime an application (based on Java/Spring/Hibernate) throws the following exception: 07:18:38.511 ERROR Error
While running the following code i am getting the error java.lang.OutOfMemoryException : java heap
The following statement creates an instance of the URL class, fills it in the
I have the following statement: var itemsFromList = from item in ListItems where item.Countries
I have the following statement. var search = PredicateBuilder.True<SomeType>(); search.And(f => false); // Still
If I execute the following statement: string.Compare(mun, mün, true, CultureInfo.InvariantCulture) The result is '-1',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.