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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:13:48+00:00 2026-06-05T01:13:48+00:00

Comparing some C-code and the F# I’m trying to replace it with, I observed

  • 0

Comparing some C-code and the F# I’m trying to replace it with, I observed that there were some differences in the final result.

Working back up the code, I discovered that even at there were differences – albeit tiny ones.

The code starts by reading in data from a file. and the very first number comes out differently. For instance, in F# (easier to script):

let a = 71.9497985840
printfn "%.20f" a

I get the expected (to me) output 71.94979858400000000000.

But in C:

a =  71.9497985840;
fprintf (stderr, "%.20f\n", a);

prints out 71.94979858400000700000.

Where does that 7 come from?

The difference is only tiny, but it bothers me because I don’t know why. (It also bothers me because it makes it more difficult to track down where my two versions of code are diverging)

  • 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-05T01:13:49+00:00Added an answer on June 5, 2026 at 1:13 am

    It’s a diifference in printing. Converting that value to an IEEE754 double yields

    Prelude Text.FShow.RealFloat> FD 71.9497985840
    71.94979858400000694018672220408916473388671875
    

    but the representation 71.949798584 is sufficient to distinguish the number from its neighbours. C, when asked to print with a precision of 20 digits after the decimal point converts the value correctly rounded to the desired number of digits, apparently F# uses the shortest uniquely determining representation and pads it with the desired number of 0s, just like Haskell does.

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

Sidebar

Related Questions

I've recently been writing some code for a research project that I'm working on,
I've got some code that relies on comparing two NSIndexPaths and executing different code
I have some simple code that is comparing two float values to illustrate a
I need some comparing and replacing code in PHP Our mission is to empower
I was trying to speed up some code, and then I tried compiling a
I just found this web page comparing some code written in Scala, C# and
Let's say I have some code that does some floating point arithmetic and stores
I'm trying to wrap some repetitive code in an extension method, to clean things
I have some image processing Java code in Android that acts upon two large
I have written some test code for comparing the performance of using direct property

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.