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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:38:10+00:00 2026-06-11T09:38:10+00:00

Those functions usually give the irrational number for a result, and are probably calculated

  • 0

Those functions usually give the irrational number for a result, and are probably calculated via taylor series but is there any documentation of how many times are those series repeated?

I’m thinking if this is sin:

public double sin(double x,int n){
    double res = 0;
    for (int i=0;i<n;i++){
        res+=Math.pow(x,i)/this.factorial(x);
    }
    return res;
}

what should the n be?
I need this because I need to create Math functions myself so I should know how many times should I repeat these operations.

thanks

  • 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-11T09:38:12+00:00Added an answer on June 11, 2026 at 9:38 am

    Calculating pow and factorial this way is very expensive and prone to rounding error. BTW I think you mean factorial(i) not (x)

    public static double sin(double x, int n) {
        double result = x;
        double term = x;
        for (int i = 3, n2 = n * 2; i <= n2; i += 2) {
            term *= -x * x / ((i - 1) * i);
            result += term;
        }
        return result;
    }
    
    public static void main(String... args) {
    /*
        for (int i = -20; i <= 20; i++) {
            double d = i / 10.0;
            System.out.println(Math.sin(d) + " vs " + sin(d, 14));
        }
    */
        double d = -1.5;
        double sin = Math.sin(d);
        System.out.println("Searching for sin(" + d + ") = " + sin);
        for (int n = 2; n <= 14; n++) {
            System.out.println(n + ": " + sin + " vs " + sin(d, n) + " err: " + (sin(d, n) - sin));
        }
    }
    

    prints

    Searching for sin(-1.5) = -0.9974949866040544
    2: -0.9974949866040544 vs -0.9375 err: 0.059994986604054446
    3: -0.9974949866040544 vs -1.00078125 err: -0.00328626339594551
    4: -0.9974949866040544 vs -0.9973911830357143 err: 1.0380356834016613E-4
    5: -0.9974949866040544 vs -0.9974971226283482 err: -2.1360242937751295E-6
    6: -0.9974949866040544 vs -0.9974949556821353 err: 3.092191913633968E-8
    7: -0.9974949866040544 vs -0.9974949869361672 err: -3.321127817201841E-10
    8: -0.9974949866040544 vs -0.9974949866013026 err: 2.751798788835913E-12
    9: -0.9974949866040544 vs -0.9974949866040727 err: -1.8207657603852567E-14
    10: -0.9974949866040544 vs -0.9974949866040544 err: 0.0
    11: -0.9974949866040544 vs -0.9974949866040546 err: -1.1102230246251565E-16
    12: -0.9974949866040544 vs -0.9974949866040546 err: -1.1102230246251565E-16
    13: -0.9974949866040544 vs -0.9974949866040546 err: -1.1102230246251565E-16
    14: -0.9974949866040544 vs -0.9974949866040546 err: -1.1102230246251565E-16
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a numeric value and on those two functions can be applied.
I'm using various functions from the earthdistance module in PostgreSQL, one of those being
A little help from those who’ve used Timthumb before. http://themes.amplus.gambit.ph/wp-content/themes/amplus/functions/timthumb.php?src=http://themes.amplus.gambit.ph/wp-content/uploads/2011/02/12979795614923485443_a1967ff888_b.jpg&w=860&h=300&f=5,255,0,0,0 This image should be
Let's say I have a UIWebView with some javascript functions. I want those javascript
Is there something like serialize/unserialize PHP functions in jQuery? These functions return a string
This is the example code, I'm using these functions for a program, but scanf
So I realize this is a possible duplicate question, as there a number of
Any idea why this might happen? I would usually think that Chrome would be
Question: Do you have any suggestion for better names for these functions? Since newpath
* UPDATE: *I've already answered my question. But you can still give me advise

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.