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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:59:49+00:00 2026-06-14T14:59:49+00:00

Possible Duplicate: Haskell ranges and floats Why does the following output occur in haskel:

  • 0

Possible Duplicate:
Haskell ranges and floats

Why does the following output occur in haskel:

[0.1,0.3..1]
[0.1,0.3,0.5,0.7,0.8999999999999999,1.0999999999999999]
  1. What is the math behind the 1.0999999999999999 (I am on a 64bit linux machine if its useful)?
  2. Why doesnt it stop at 0.8999999999999999 when obviously 1.0999999999999999 is out of range?
  • 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-14T14:59:50+00:00Added an answer on June 14, 2026 at 2:59 pm

    Why the overshoot?

    [0.1,0.3..1] is short for enumFromThenTo 0.1 0.3 1.0

    The Haskell report says

    For Float and Double, the semantics of the enumFrom family is given by the rules for Int above, except that the list terminates when the elements become greater than e3 + i∕2 for positive increment i, or when they become less than e3 + i∕2 for negative i.

    Here e3 = 1.0 and your increment i = 0.2, so e3 + i∕2 = 1.1. It’s only supposed to stop when it goes bigger than that.

    You asked it to stop at 1, but it can only stop at 0.9 or 1.1. There’s a rounding error (floating types are inherently inaccurate) and 1.1 has ended up as 1.09999999999, so since this is not greater than 1.0 + i/2, it’s allowed.

    In fact, even if it were equal to 1.0+i/2 it’s allowed, as you can check using the exact [0.1,0.3..1]::[Rational] (after importing Data.Ratio).

    You can avoid the problem by calculating the upper limit you’re aiming for, 0.9, and specifying that: [0.1,0.3..0.9]. You won’t suffer from rounding error unless your increment is small and your numbers are large, i.e. you’re working beyond the accuracy of Double for large numbers.

    Why the inaccuracy?

    1.09 recurring is mathematically indistinguishable from 1.1, but here we have a finite number of 9s, and that’s strictly less than 1.1.

    Floating point numbers are stored as if they’re in scientific notation, eg 4.563347×10^-7, but in binary, so like 01.1001110101×2^01101110.

    This means your number can only be stored completely accurately as a Float if you can express it by summing powers of two, just as you can only write a number in decimal if you can express is by summing powers of 10.

    0.2 in your example is 0.001100110011 in binary, with the 0011 repeating forever and 1.1 is 1.0001100110011 again with 0011 repeating forever.

    Since only a finite part of those will be stored, when converted back to decimal to show you, they’ll be a little out. Often the difference is so small it gets rounded away again, but sometimes you can see it, as here.

    This inherent inaccuracy is why enumFromThenTo lets you go above the top number – it’s stopping you from having too few because of rounding errors.

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

Sidebar

Related Questions

Possible Duplicate: Haskell ranges and floats If I generate a list in ghci like
Possible Duplicate: How to tell if a list is infinite? In Haskell, you can
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Haskell vs. procedural programming in the real world Few times I heard
Possible Duplicate: Currying subtraction I started my first haskell project that is not from
Possible Duplicate: Replace individual list elements in Haskell? I have managed to make some
Possible Duplicate: Creating unique labels in Haskell I've got a datatype Person and some
Possible Duplicate: Iterating through a String and replacing single chars with substrings in haskell
Possible Duplicate: Java's Interface and Haskell's type class: differences and similarities? When I started
Possible Duplicate: Reference - What does this symbol mean in PHP? I am looking

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.