LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-27-2007, 01:24 AM   #1
haxpor
Member
 
Registered: Dec 2006
Distribution: Ubuntu 20.04
Posts: 87

Rep: Reputation: 15
How can I declare "New Datatype" in C?


Some situation, involved calculation that is very large where you must allowcate some bits of memory to be larger than the standard type that C has.
So i want to know "How can I declare new type (for my arbitrary numbers of bits, says 1024 bits or something)?".

Or any ideas for that could be great, thanks.
 
Old 07-27-2007, 02:00 AM   #2
excel28
Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 72

Rep: Reputation: 15
You can look at OpenSSL. They deal with large numbers too. One of the big numbers structures is called BIGNUM.
 
Old 07-27-2007, 03:14 AM   #3
haxpor
Member
 
Registered: Dec 2006
Distribution: Ubuntu 20.04
Posts: 87

Original Poster
Rep: Reputation: 15
excel28, thanks for pointing me to the right source BUT i am not yet know the answer.

I am now looking at BIGNUM structure (BIGNUM is name for bignum_st, real structure) in include/bn.h.
It defined as follow,

Code:
struct bignum_st
{
  BN_ULONG *d;	/* Pointer to an array of 'BN_BITS2' bit chunks. */
  int top;	/* Index of last used d +1. */
  /* The next are internal book keeping for bn_expand. */
  int dmax;	/* Size of the d array. */
  int neg;	/* one if the number is negative */
  int flags;
};
Also I see from the comment that lead to bn_expand in the same file, but now I just trying to look at it.

I keep trying...
 
Old 07-27-2007, 05:07 AM   #4
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
Well C can only store data types that are big enough to be stored into a register on the computer so in essence you can only have one large enough to fit into one of them. Of course this is not a limitation as you can do some "magic" and get larger numbers to fit. I think the largest you can have is a unsigned long.
 
Old 08-01-2007, 03:54 AM   #5
haxpor
Member
 
Registered: Dec 2006
Distribution: Ubuntu 20.04
Posts: 87

Original Poster
Rep: Reputation: 15
Hmm,
If so, then in science situation in real world. How can they manage to calculate that thing? (I dont know really)
 
Old 08-01-2007, 05:34 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
by very clever manipulation of memory and registers
 
Old 08-01-2007, 08:00 AM   #7
psisquare
Member
 
Registered: Sep 2004
Location: Germany
Distribution: Gentoo
Posts: 164

Rep: Reputation: 31
As you can see from the OpenSSL source, arbitrary precision calculations in C are highly non-trivial. Fortunately, there are libraries to ease this task, for example GMP.
 
Old 08-01-2007, 12:10 PM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Well, if it makes things a little more clear: In general, all of the arithmetic operations performed on built-in types are defined in asm, and therefore directly correlate to single processor operations. To go outside of those boundaries requires functions written in terms of operations on built-in types. Would you know how to calculate 1234 / 4321 not allowing any portion of the calculation to exceed 2 digits? I have no idea how to do that. Ever wonder why it takes forever to make extremely accurate scientific calculations? I think GMP is your best bet as psisquare said.
ta0kira
 
Old 08-04-2007, 01:35 AM   #9
haxpor
Member
 
Registered: Dec 2006
Distribution: Ubuntu 20.04
Posts: 87

Original Poster
Rep: Reputation: 15
Ok, thanks everyone. I will try that.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 03:07 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
Yum: "requested datatype primary not available" Zeppe|in Linux - Software 0 02-22-2007 07:48 AM
Any way to get "Alice"; "Call of Duty" series and "Descent 3" to work? JBailey742 Linux - Games 13 06-23-2006 01:34 PM
defining "+" operator for new datatype TexasDex Programming 7 04-03-2004 10:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration