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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:39:10+00:00 2026-06-07T20:39:10+00:00

Possible Duplicate: Retain precision with Doubles in java Do you know the difference between

  • 0

Possible Duplicate:
Retain precision with Doubles in java

Do you know the difference between these two operations in Java.

final double m1 = 11d / 1e9; // gives 1.1e-8
final double m2 = 11d * 1e-9; // gives 1.1000000000000001e-8

I see in the generated bytecode that the precompiled result of m2 is already not what I expected.
In the output of javap -verbose -c I can see the following value :

const #3 = double   1.1E-8d;
[...]
const #6 = double   1.1000000000000001E-8d;

When I use m1 or m2 in other expressions, I don’t have the same result.

When I try the same thing in C, m1 and m2 is strictly 1.1e-8

I think my problem is in the way java handles double precision computation but I can’t explain myself what I miss.

  • 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-07T20:39:12+00:00Added an answer on June 7, 2026 at 8:39 pm

    The difference you have is that 1e9 is exactly representable and 1e-9 which is not exactly representable. A small representation error results in an arithmetic error which you can see.

    System.out.println(new BigDecimal(1e9));
    System.out.println(new BigDecimal(1e-9));
    

    prints

    1000000000
    1.0000000000000000622815914577798564188970686927859787829220294952392578125E-9
    

    The difference is not whether you have used * or / but that you have used a whole number in one case and a fraction in the other.

    System.out.println(11 * 1e9);
    System.out.println(11 * 1e-9);
    

    prints

    1.1E10
    1.1000000000000001E-8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Retain precision with Doubles in java Floating point inaccuracy examples I know
Possible Duplicate: Retain precision with Doubles in java Moving decimal places over in a
Possible Duplicate: Retain precision with Doubles in java import static java.lang.System.out; public class q2{
Possible Duplicate: Difference between retain and copy? I'm learning iOS development right now and
Possible Duplicate: Why use 'self.' when its not forced? What is the difference between
Possible Duplicate: Properties and Instance Variables in Objective-C 2.0 I'm confused by these two
Possible Duplicate: NSNumber retain count issue Hello, I have the following code: NSNumber *number
Possible Duplicate: Atomic vs nonatomic properties I just want to know what is the
Possible Duplicate: How is release handled for @synthesized retain properties? I saw someone mention
Possible Duplicate: Locking main() thread Below you'll find my code, Main calls two threads,

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.