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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:10:09+00:00 2026-05-26T17:10:09+00:00

Sorry, this is nothing about image, I just don’t know how to ask the

  • 0

Sorry, this is nothing about image, I just don’t know how to ask the question properly.

My question is, I am writing a C++ code, and doing a calculation.

a=b*cos(c)

b is varying with time from zero to its amplitude, say bmax. (actually, b=bmax*sin(t).)

However, I found when b is very small, the result a is gradually deviating from my analytic results.

So I am wondering how to keep a very high resolution of the results, to avoid the cut-off of the floating points.

  • 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-26T17:10:09+00:00Added an answer on May 26, 2026 at 5:10 pm

    When you say it’s gradually deviating it sounds like you’ve got an accumulation of error there (although there’s nothing obvious in the code you posted). For example this code the error accumulates with every iteration around the while loop:

    #include <iostream>
    
    int main() {
      unsigned short counter;
      float val = 0;
      while (counter++) {
        val += 0.001f;
        std::cout << val << "\n";
      }
    }
    

    Where as re-writing it like:

    #include <iostream>
    
    int main() {
      unsigned short counter;
      while (counter++) {
        float val = counter * 0.001f;
        std::cout << val << "\n";
      }
    }
    

    does not cause this accumulation of error as val only depends upon the integer (which is exactly representable) and not the previous values of val each of which will have introduced some small error.

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

Sidebar

Related Questions

Sorry for asking a question about something I don't know much about, but I've
Sorry, but I know nothing at all about fonts, so I hope that this
Sorry this is not a very well defined question, I am thinking about an
Sorry this is a basic question, but all my research just barely missed answering
Sorry for the probably stupid question. Since I found nothing about it on the
I'm sorry about the title I'm just not sure how to describe this one.
sorry this is such a simple question but I can't figure it out. How
Sorry if this is a stupid question... I've developed an application that creates absolute
Sorry if this is a really basic question but it's been really getting to
Sorry if this question is too vague, but I'd rather not muddy it's point

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.