2 Replies - 4150 Views - Last Post: 08 January 2008 - 06:43 AM Rate Topic: -----

#1 qdoom  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 82
  • Joined: 31-August 06

HugeDecimals?: Taylor Series

Posted 06 January 2008 - 12:15 PM

I'm writing a program, that calculates cos(1), using Taylor series. That would really be not that hard:

using System;

namespace TaylorSeriesCosOne
{
	class Program
	{
		static void Main(string[] args)
		{
			double cosOne = 1;
			int n = 2;
			int factorial = 1;
			double power = 1;

			while (n <= 14)
			{
				power = power * -1;
				factorial = factorial * n * (n - 1);
				cosOne = cosOne + (power / factorial);

				Console.WriteLine("n: {0} \tcosOne: {1}", n, cosOne);

				n = n + 2;
			}

			Console.WriteLine("\ncos(1) = {0}", cosOne);

			Console.ReadLine();
		}
	}
}


But... The problem: it's not really an accurate answer. And I want it to be a lot more accurate (more than 10^(-1000), for example). My first thought was to write HugeInteger and HugeDecimal classes (well, parts of them, that I would use in this program). I'm just not sure, if that's the easiest way to do it. I'm not in a hurry with this, so I thought, that I'll just post here and ask if anyone have any suggestions.

Is This A Good Question/Topic? 0
  • +

Replies To: HugeDecimals?: Taylor Series

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5932
  • View blog
  • Posts: 12,855
  • Joined: 16-October 07

Re: HugeDecimals?: Taylor Series

Posted 06 January 2008 - 01:08 PM

There's nothing native that I'm aware of... However, really, really big numbers are required for cryptography, so that could be a starting point.

A quick google found me few BigInt type classes:
http://blogs.msdn.co...nbar-gazit.aspx
http://www.codeproje...biginteger.aspx
http://www.developer...o.uk/show/4670/

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#3 qdoom  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 82
  • Joined: 31-August 06

Re: HugeDecimals?: Taylor Series

Posted 08 January 2008 - 06:43 AM

Thanks.

I'm done with BigInt (well, the +/- etc. part of it). Now, I have the fraction (cosOne.power / cosOne.factorial) in BigInt. The only thing, that's left is division (cosOne.power / cosOne.factorial to get the answer become decimal from fraction). Time to get a sheet of paper and figure out how to do that one. If anyone has any suggestions (or pseudocode :P), please don't hesitate to post a reply. :rolleyes:

This post has been edited by qdoom: 08 January 2008 - 12:49 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1