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

  • Home
  • SEARCH
  • 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 7420827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:18:24+00:00 2026-05-29T08:18:24+00:00

In order to prevent DivideByZeroException in C#, people often write things like double f(double

  • 0

In order to prevent DivideByZeroException in C#, people often write things like

double f(double x) {
  if (x != 0.0) return 1000.0/x;
  else return 0.0;
}

Given the fact that floating-point arithmetic always has imprecisions, I wonder whether it is guaranteed that this function never throws a DivideByZeroException.

  • 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-05-29T08:18:25+00:00Added an answer on May 29, 2026 at 8:18 am

    The documentation says:

    Dividing a floating-point value by zero will result in either positive infinity, negative infinity, or Not-a-Number (NaN) according to the rules of IEEE 754 arithmetic. Floating-point operations never throw an exception. For more information, see Single and Double.

    So yes, “it is guaranteed that this function never throws a DivideByZeroException.” – even without any checking, but it may return positive infinity, negative infinity, or Not-a-Number (NaN) even if you check for 0.0, for example when you divide a rather large value by a really small value so that the result exceeds the range covered by double.

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

Sidebar

Related Questions

In order to prevent file storage problems like when two people upload a file
I have a table which stores 'links' between 2 people. In order prevent further
It is said that in order to prevent from SQL injection one should filter
I just found out that in order to prevent full table scans during joins,
Some people have used prefixes to name their category methods in order to prevent
I'd like to disable a form after it is submitted in order to prevent
In order to prevent somebody from grabbing my data easily, I cache data from
In order to prevent a SQLite in-memory database from being cleaned up, one must
how can I catch windows taskkill command in order to prevent it?
Do I need to do anything in order to prevent inserts/updates/deletes/injection attacks when I'm

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.