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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:50:28+00:00 2026-05-26T19:50:28+00:00

the situation is drammatic… It’s 5 days that i must resolve this problem and

  • 0

the situation is drammatic… It’s 5 days that i must resolve this problem and i can’t get out.

The problem: a simple operation as a product make always wrong result. Why?

Extract of the code:

//all vars are float
// resultVec is a vector [3]
// Rs is a vector [3]
// accelerationvalues is a vector [3]
   resultVec[0]=Rs[0]*accelerationvalues[0]+Rs[1]*accelerationvalues[1]+Rs[2]*accelerationvalues[2];

//debug to print result

Log.d("e", "("+Rs[0]+")*("+accelerationvalues[0]+")+("+Rs[1]+")*("+accelerationvalues[1]+")+("+Rs[2]+")*("+accelerationvalues[2]+")="+(resultVec[0]));

And this is the Log Cat result:
enter image description here
But you can simply try that this is wrong: search on google

(0.040147018)*(-0.9942854)+(0.9984244)*(-0.32688835)+(0.039202508)*(9.343558)

And you’ll find that the true result is 8.67678679 × 10-9 that is very different from the other..This error is repeated always i execute the programm, some time the difference is in the sign too!

What is the problem?

I’ve tried all the way to solve it! (some are posted below):

You can find the full source here.

  1. save Rs and accelerationvalues in an arraylist and perform calculation outside the listner. No result.
  2. Convert float to double, no result.
  3. Many others ways

P.S. This problem occour only for resultVec[0] and resultVec[1], instead resultVec[2] is well calculated.

  • 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-26T19:50:29+00:00Added an answer on May 26, 2026 at 7:50 pm

    This is not android’s fault, it is how you designed the app.

    Execute this in a plain Java application:

    public class ArithmTest {
    
        public static void main(String[] args) {
            double d1 = (0.040147018)*(-0.9942854)+(0.9984244)*(-0.32688835)+(0.039202508)*(9.343558);
            System.out.println(d1);
    
            float f1 = 0.040147018f;
            float f2 = -0.9942854f;
    
            float f3 = 0.9984244f;
            float f4 = -0.32688835f;
    
            float f5 = 0.039202508f;
            float f6 = 9.343558f;
    
            System.out.println(f1*f2 + f3*f4 + f5*f6);
    
        }
    }
    

    As you can see, the first one is the same as Google’s, and the second printout is your app’s value.
    To solve this, I think you should use double instead of float in every variable you declared, e.g.: accelerationvalues and resultVec.

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

Sidebar

Related Questions

Situation: Get-ChildItem $Path -Filter *.dll works for me This works: $Path = $env:windir\system32\* $GuyArray
Situation with Thai text on a client site is that we can't control where
Situation: A high-scale Azure IIS7 application, which must do this: Receive request Place request
Situation: I have a simple XML document that contains image information. I need to
Situation: text: a string R: a regex that matches part of the string. This
Situation: I am trying to construct a simple method that accepts two different integers
Situation is simple: I post a plain HTML form with a textarea. Then, in
Situation: I often run into this problematic and never know how to solve it.
Situation is simple. I need to wrap text around two inline objects (buttons with
Situation: I have some persons with certain skills and they can/might belong to more

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.