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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:52:47+00:00 2026-05-31T17:52:47+00:00

Possible Duplicate: Haskell ranges and floats If I generate a list in ghci like

  • 0

Possible Duplicate:
Haskell ranges and floats

If I generate a list in ghci like so

let a = [0.1,1..10]

This gives me a list a with the following entries

[0.1,1.0,1.9,2.8,3.6999999999999997,4.6,5.5,6.4,7.300000000000001,8.200000000000001,9.100000000000001,10.000000000000002]

The last element of the list is 10.000000000000002, I assume this is just due to floating point use. However, comparing with the number 10 the result seems inconsistent, e.g,

last a > 10
True

last a < 10
False

Why is the list creation not comparing if the final element is less than or equal to the 10?

  • 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-31T17:52:49+00:00Added an answer on May 31, 2026 at 5:52 pm

    Arithmetic sequences of floating point numbers stop when the value goes greater than the final value plus 1/2, per the reference implementation of the Prelude:

    numericEnumFrom         :: (Fractional a) => a -> [a]  
    numericEnumFromThen     :: (Fractional a) => a -> a -> [a]  
    numericEnumFromTo       :: (Fractional a, Ord a) => a -> a -> [a]  
    numericEnumFromThenTo   :: (Fractional a, Ord a) => a -> a -> a -> [a]  
    numericEnumFrom         =  iterate (+1)  
    numericEnumFromThen n m =  iterate (+(m-n)) n  
    numericEnumFromTo n m   =  takeWhile (<= m+1/2) (numericEnumFrom n)  
    numericEnumFromThenTo n n' m = takeWhile p (numericEnumFromThen n n')  
                                 where  
                                   p | n' >= n   = (<= m + (n'-n)/2)  
                                     | otherwise = (>= m + (n'-n)/2)
    

    As for why, you’d have to ask the Committee, but it’s likely that they didn’t want a range to end up “incomplete”, and thought having it a bit too large would be less unintuitive. With floating point, it’s always going to be one or the other.

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

Sidebar

Related Questions

Possible Duplicate: How to tell if a list is infinite? In Haskell, you can
Possible Duplicate: Replace individual list elements in Haskell? I have managed to make some
Possible Duplicate: convert string list to int list in haskell I have a string
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: Haskell vs. procedural programming in the real world Few times I heard
Possible Duplicate: How can I combine multiple rows into a comma-delimited list in Oracle?
Possible Duplicate: php == vs === operator Reference - What does this symbol mean
Possible Duplicate: Java's Interface and Haskell's type class: differences and similarities? When I started
Possible Duplicate: Sort a list of tuples by their second elements Hey there i
So I realize this is a possible duplicate question, as there a number 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.