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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:19:55+00:00 2026-05-28T15:19:55+00:00

A calculator program I have created works almost perfectly with the exception that Math.Sin()

  • 0

A calculator program I have created works almost perfectly with the exception that Math.Sin() and Math.Log() seem to have some inaccuracies that I can’t seem to get to the bottom of. I will try give as much detail as I can.

Math.Sin() Problem:

First, this is NOT a radian problem (at least so far as I can tell). Numbers are fed to Math.Sin() as double. It works for some values in both degrees and radians but not for others like 180 and pi respectively. Now for some code:

    private void buttonSin_Click(object sender, EventArgs e)
    {
        if (radioDeg.Checked)
        {
            firstOperand = Math.PI/180*firstOperand;
        }
        firstOperand = Math.Sin(firstOperand);
        secondOperand = 0;
        displayScreen.Text = firstOperand.ToString();
        clickCount = 0;
        operationCount++;
    }

firstOperand is double and is (along with secondOperand) used for subsequent calculations that would take place. I think other parts of the code are self-explanatory but I’ll be happy to elaborate if necessary. Math.Sin(Math.PI)=1.224… instead of 0 as it should. However Math.Sin(Math.PI/4)=0.707… as expected. Furthermore, this is only when pi is generated as Math.PI. If entered in manually as 3.14159, Math.Sin()=2.65… If entered in as 3.1415926 I get Math.Sin()=5.35… Can anyone point out why?

Math.Log() Problem:

This part works almost perfectly. The only error occurs when the function is applied successively. Take a look at the code:

    private void buttonLn_Click(object sender, EventArgs e)
    {
        firstOperand = Math.Log(firstOperand);
        secondOperand = 0;
        displayScreen.Text = firstOperand.ToString();
        clickCount = 0;
        operationCount++;
    }

Math.Log(Math.E)=1 as it should, but when the ln button is hit immediately thereafter, I get a value of 1.776… Note that if 2.718 is entered in manually and then the ln button is hit twice in succession, I get -.0001… which is much closer to the actual answer of 0.

I’m sorry if these should be separate posts, but I thought both problems might relate to how constants Math.PI and Math.E are handled. Any thoughts?

  • 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-28T15:19:56+00:00Added an answer on May 28, 2026 at 3:19 pm

    Check your exponents. When I evaluate Math.Sin(Math.Pi) here in VS 2010 debug evaluator, I see this: 0.00000000000000012246063538223773

    That would be output as 1.224e-16.

    Either way, it’s just a hair’s breadth from zero. As with many floating point operations, close enough should be considered zero.

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

Sidebar

Related Questions

I have a very basic Visual Basic Program that I created in Visual Studio
in my C#-Silverlight-3-Application, I have created a class, that is doing some calculations that
I have a program that will calculate the minimal area taken by fitting rectangles
I have a benchmarking program that calculates the time (in milliseconds and ticks), for
I have a python program/file that I want to run repeatedly and calculate the
I'm having some trouble returning multiple values in this program that calculates min, max,
I have a winform program that allows users to upload Shockwave Flash movies to
I have created a program with a 30 day trial period in VB.Net. The
I have created a simple program to calculate primes as follows: var db =
i created a program in javascript that computes vector coordinates, everything was smooth since

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.