# HugeDecimals?: Taylor Series

Page 1 of 1

## 2 Replies - 5891 Views - Last Post: 08 January 2008 - 06:43 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=40455&amp;s=d2565b99ec5909007162cdadc2d7111a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 qdoom

Reputation: 1
• 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);

}
}
}
```

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

• Dreaming Coder

Reputation: 7166
• Posts: 14,933
• 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.

### #3 qdoom

Reputation: 1
• 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 ), please don't hesitate to post a reply.

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