It looks like you're new here. If you want to get involved, click one of these buttons!

- 141.3K All Categories
- 104.6K Programming Languages
- 6.4K Assembler Developer
- 1.9K Basic
- 39.8K C and C++
- 4.3K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.6K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 514 Python
- 48 Ruby
- 4.3K VB.NET
- 1.6K VBA
- 20.8K Visual Basic
- 2.6K Game programming
- 311 Console programming
- 89 DirectX Game dev
- 1 Minecraft
- 110 Newbie Game Programmers
- 2 Oculus Rift
- 8.9K Applications
- 1.8K Computer Graphics
- 729 Computer Hardware
- 3.4K Database & SQL
- 522 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 256 XML Development
- 3.3K Classifieds
- 195 Co-operative Projects
- 183 For sale
- 189 FreeLance Software City
- 1.9K Jobs Available
- 600 Jobs Wanted
- 201 Wanted
- 2.9K Microsoft .NET
- 1.7K ASP.NET
- 1.1K .NET General
- 3.3K Miscellaneous
- 4 Join the Team
- 0 User Profiles
- 349 Comments on this site
- 59 Computer Emulators
- 2.1K General programming
- 179 New programming languages
- 610 Off topic board
- 167 Mobile & Wireless
- 41 Android
- 124 Palm Pilot
- 335 Multimedia
- 151 Demo programming
- 184 MP3 programming
- 0 Bash scripts
- 19 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 367 MS-DOS
- 0 Shell scripting
- 320 Windows CE & Pocket PC
- 4.1K Windows programming
- 889 Software Development
- 406 Algorithms
- 68 Object Orientation
- 87 Project Management
- 90 Quality & Testing
- 237 Security
- 7.5K WEB-Development
- 1.8K Active Server Pages
- 61 AJAX
- 2 Bootstrap Themes
- 55 CGI Development
- 19 ColdFusion
- 222 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 34 JQuery
- 284 WEB Servers
- 149 WEB-Services / SOAP

VanilleBert
Posts: **29**Member

in .NET General

Hi coders,

I want to calculate big prime numbers. To test if a number is prime i want to use the Mille-Rabin-Algo, but the calculation of "2^x" (for x > 1023) isn't possible with datatypes like "double". The result is simply to big. For example my C# calc says that "(2^1024) - (2^1024 + 1)" isn't 1. To calculate numbers of arbitary size i can't use the standardized datatypes of C# .NET.

The GNU MP is a package to handle with numbers of arbitary size. But it is programmed for C and GNU compilers.

My question is: Is there a useful package for C# .NET to calc numbers of arbitary size?

Though they know that bignums are essential for scientific calcs, MS wasn't so friendly to bring a bignum datatype with the .NET Framework.

I want to calculate big prime numbers. To test if a number is prime i want to use the Mille-Rabin-Algo, but the calculation of "2^x" (for x > 1023) isn't possible with datatypes like "double". The result is simply to big. For example my C# calc says that "(2^1024) - (2^1024 + 1)" isn't 1. To calculate numbers of arbitary size i can't use the standardized datatypes of C# .NET.

The GNU MP is a package to handle with numbers of arbitary size. But it is programmed for C and GNU compilers.

My question is: Is there a useful package for C# .NET to calc numbers of arbitary size?

Though they know that bignums are essential for scientific calcs, MS wasn't so friendly to bring a bignum datatype with the .NET Framework.

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven LLC

© 1997-2015 Programmersheaven.com - All rights reserved.

## Comments

1,784Member29Memberhuh?

1,784Member:

: I want to calculate big prime numbers. To test if a number is prime i want to use the Mille-Rabin-Algo, but the calculation of "2^x" (for x > 1023) isn't possible with datatypes like "double". The result is simply to big. For example my C# calc says that "(2^1024) - (2^1024 + 1)" isn't 1. To calculate numbers of arbitary size i can't use the standardized datatypes of C# .NET.

:

: The GNU MP is a package to handle with numbers of arbitary size. But it is programmed for C and GNU compilers.

:

: My question is: Is there a useful package for C# .NET to calc numbers of arbitary size?

:

: Though they know that bignums are essential for scientific calcs, MS wasn't so friendly to bring a bignum datatype with the .NET Framework.

:

Sorry, this site had some problems before... But now it works. I forget about this one...

My answear to your Q was to use the decimal type. It's floating point, but it doesn't matter...

It holds 20 digits or so I think. It's made to hold really big numbers, wich you want.

One reason for there isn't such a package in .net is that it isn't possible to program good in .net . In all other languages it's easy, just use a pointer and add with carry.

In asm it'll look like this:

[code]

;program to add 2 64 bit numbers at bx,dx and store at di

mov ax,0

mov cx,0

add ax,cx ;clear carry flag... (I can't remember the instruction for this...)

rept 4 counter{

mov ah,[bx+4-counter]

mov ch,[dx+4-counter]

adc ah,ch

mov [di+4-counter],ah

}

[/code]

The number 4 is the number of bytes the data is. It's possible to add 128bit numbers like this.

[grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]

29Member: It holds 20 digits or so I think. It's made to hold really big : numbers, wich you want.

"decimal" is even smaller than "double". And it is not my aim to hold really big numbers, i talk about 2^10000 and much more.

type maximum

ulong 1.84*(10^19)

decimal 7.9*(10^28)

float 3.4*(10^38)

double 1.7*(10^308) !!

??? endless

: One reason for there isn't such a package in .net is that it isn't : possible to program good in .net . In all other languages it's easy, : just use a pointer and add with carry.

huh? I think .NET is the easiest SDK since Borlands VCL.

A pointer could hold everything, but i need to handle this numbers. I want to use predefined addition, multiplication, division, modulation and the ^-thing(don't know the english word).

thx for response.

Bert.

PS: nice homepage

1,784Member: : My answear to your Q was to use the decimal type. It's floating point, : but it doesn't matter...

: : It holds 20 digits or so I think. It's made to hold really big : numbers, wich you want.

:

: "decimal" is even smaller than "double". And it is not my aim to hold really big numbers, i talk about 2^10000 and much more.

:

: type maximum

: ulong 1.84*(10^19)

: decimal 7.9*(10^28)

: float 3.4*(10^38)

: double 1.7*(10^308) !!

: ??? endless

:

: : One reason for there isn't such a package in .net is that it isn't : possible to program good in .net . In all other languages it's easy, : just use a pointer and add with carry.

:

: huh? I think .NET is the easiest SDK since Borlands VCL.

[blue]Yes, but it doesn't got add with carry, and you can't asm in it... (I'll maybe learn msil, and do something like this in it)[/blue]

: A pointer could hold everything, but i need to handle this numbers.

[blue]Look at my asm code. It's OK if you don't understand it, but the thing with it is that it can add BIG numbers like 256 bit. It requieres pointers and add with carry though.[/blue]

:I want to use predefined addition, multiplication, division, modulation :and the ^-thing(don't know the english word).

[blue]^ is called raised to in english. In C/C++ this ^ symbols the xor operation, wich is compleatly different. I'm swedish, and didn't know what it was named before eather.[/blue]

: thx for response.

:

: Bert.

:

: PS: nice homepage

:

My webhost is down, so I can't do anything with it :-(

1,784Member: : ulong 1.84*(10^19)

: : decimal 7.9*(10^28)

: : float 3.4*(10^38)

: : double 1.7*(10^308) !!

: : ??? endless

: :

ulong = 2^64

double * (2^ulong)

1.7*(10^308) * (2^(2^64))

I think that's big enough....

So now I'm doing a struct that will do this.

Do you want me to send you the code when I'm done?

29Member: double * (2^ulong)

: 1.7*(10^308) * (2^(2^64))

:

: I think that's big enough....

: So now I'm doing a struct that will do this.

this would be about 1.7*(10^327). This isn't big enough and i think you don't understand. I need numbers of arbitary size(there is no "big enough") and special operators which handle these numbers. My calculation is "a^(n-1) mod n; (n,a element of naturals & unknown size)". n is maybe "(2^25964951)-1", this is a number with 7816230 decimals. A datatype with a size of (10^7816230)!

1,784Member: : double * (2^ulong)

: : 1.7*(10^308) * (2^(2^64))

: :

: : I think that's big enough....

: : So now I'm doing a struct that will do this.

:

: this would be about 1.7*(10^327). This isn't big enough and i think you don't understand.

If I first make a small type then it would be easy to make it bigger.

: I need numbers of arbitary size(there is no "big enough") and special

: operators which handle these numbers. My calculation is "a^(n-1) mod n;

Why didn't you say so. This is easy to cheat.

If you'll think a little it's easy to do this.

What you want is x^y mod z to simplify.

You really don't want to have that big x^y but only the small value of

x^y mod z.

Hardcode some math and it will work with int.

There's lots of people who do it like you.

One of them invented a really interesting fast power formula...

29Member[1] Download & Install "Visual J# .Net Redistributable Package"

In IDE: Add Reference "vjslib"

In Code:

[code]

using java.math;

BigInteger n = new BigInteger("123456789");

BigDecimal d = new BigDecimal("123456789.987654321");

[/code]

[1] http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=301f28aa-49b6-4b32-832c-873707e50834