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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:31:32+00:00 2026-05-14T23:31:32+00:00

strange situation, when performing the following lines of Code: const float a = 47.848711;

  • 0

strange situation, when performing the following lines of Code:

const float a = 47.848711;
const float b = 47.862952;
float result = b - a;

I get a (NSLog %.10f) result = 0.0142440796.

I expected to get 0.0142410000.

What’s going on?

  • 1 1 Answer
  • 2 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-14T23:31:32+00:00Added an answer on May 14, 2026 at 11:31 pm

    What if I ask you the following:

    const int a = 1.3;
    const int b = 2.7;
    int result = b - a;
    

    I get a (NSLog %d) result = 1.

    I expected to get 1.4. What’s going on?

    In this case, the answer is obvious, right? 1.3 isn’t an integer, so the actual value that gets stored in a is 1, and the value that gets stored in b isn’t 2.7, but rather 2. When I subtract 1 from 2 I get exactly 1, which is the observed answer. If you’re with me so far, keep reading.


    The exact same thing is happening in your example. 47.848711 isn’t a single-precision float, so the closest floating-point value is stored in a instead, which is exactly:

    a = 47.8487091064453125
    

    Similarly, the value stored in b is the closest floating-point value to 47.862952, which is exactly:

    b = 47.86295318603515625
    

    When you subtract these numbers to get result, you get:

      47.86295318603515625
    - 47.8487091064453125
    ----------------------
       0.01424407958984375
    

    When you round that value to 10 digits to print it out, you get:

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

Sidebar

Related Questions

Strange situation: I am trying to remove some hard coding from my code. There
Very strange situation here: I'm using L2S to populate a DataGridView. Code follows: private
I've run into a strange situation that seems to involve long text overflowing. I'm
I'm seeing strange errors when my C++ code has min() or max() calls. I'm
Strange situation - examples from apple works, but after i change them a bit,
Bumped into a strange situation here. Trying to extract cars from a sql database
I've got a strange situation where deleting and creating directories in quick succession on
I've got a strange situation with some tables in my database starting its IDs
I have a strange situation. I have to use NVL(columna, columnb) in Oracle and
I have a very strange situation happening and I'm hoping someone here knows why.

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.