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 7518289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:43:48+00:00 2026-05-30T01:43:48+00:00

I found a quite strange inconsistency between the behaviour of div and / .

  • 0

I found a quite strange inconsistency between the behaviour of div and /.

*ghci> :t 1 `div` 0
1 `div` 0 :: Integral a => a
*ghci> :t 1 / 0
1 / 0 :: Fractional a => a
*ghci> 1 / 0
Infinity
*ghci> 1 `div` 0
*** Exception: divide by zero

I was quite surprised to notice that the fractional division by zero leads to Infinity, whereas div correctly leads to an exception.
A NaN could be acceptable too for /, but why Infinity? There is no mathematical justification for such a result. Do you know the reason for this, please?

  • 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-30T01:43:49+00:00Added an answer on May 30, 2026 at 1:43 am

    The reason that div does not return Infinity is simple–there is no representation for infinity in the Integer type.

    / returns Infinity because it follows the IEEE 754 standard (which describes floating point number representations) since the default Fractional type is Double. Other languages with floating point numbers (e.g. JavaScript) also exhibit this behavior.

    To make mathematicians cringe even more, you get a different result if you divide by negative 0, despite the fact that -0 == 0 for floats:

    Prelude> 1/(-0)
    -Infinity
    

    This is also behavior from the standard.

    If you use a different fractional type like Rational, you will get the behavior you expect:

    Prelude> 1 / (0 :: Rational)
    *** Exception: Ratio.%: zero denominator
    

    Coincidentally, if you’re wondering about why Integer and Double are the types in question when your actual operation does not reference them, take a look at how Haskell handles defaulting types (especially numeric types) in the report.

    The short version is that if you have an ambiguous type from the Num class, Haskell will first try Integer and then Double for that type. You can change this with a default (Type1, Type2...) statement or turn it off with a default () statement at the module level.

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

Sidebar

Related Questions

I was quite surprised when I found out that for x <- array(0, c(5,3,1))
I've found a quite strange behavior if I try to post to a user
From the ethreal packet capture, I see the following behaviour which appears quite strange
I know it's been asked around but I haven't found quite the answer yet
I've looked through several posts but I haven't quite found any answers that have
I'm fairly new to node.js and I've found its quite complicated separating a project
I've read through a number of topics now and have not found one quite
Having recently learned of the DebuggerDisplay attribute, I've found it quite useful. However, one
I have searched and found another with quite close question but the result was
I'm doing some VBA development and I found creating SQLs quite efficient way of

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.