Click here to Skip to main content
12,754,607 members (34,910 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 15 Dec 2005

Lint: Large Integer Object Library

, 15 Dec 2005
Rate this:
Please Sign up or sign in to vote.
Lint is a signed large integer data type class library.


Lint is a signed large integer data type class library that supports all mathematical operators available to other intrinsic integer data types. The precision is not arbitrary as in other available libraries. Rather, the number of bits that make up a lint variable is dependent on the value of a #define directive declared in the header file.


So why yet another large integer library? Several reasons, among which:

  • I wanted a class that supported all possible overloaded operators so that I could use a lint just exactly like I might use an intrinsic data type such as an int or long. None of the free implementations I could find seemed to support all over-loadable operators.
  • I wanted a class that was specifically created with Visual C++ and IA-32 based PC architecture in mind. I didn't want a library that sacrificed execution speed for the sake of cross-compiler and cross-platform compatibility. I wanted a library that I could optimize with in-line assembly code.
  • I wanted a class whose methods were as fast and efficient as possible. Arbitrary-precision logic and floating point logic bring with them a performance hit. This library is efficient because precision is not arbitrary and all operations are strictly integer based. In this way, I could write highly optimized assembly routines given a known data type and size.

Using the code

Once you include the header file in your source, using a lint is similar to using any other numeric data type in C++. The few notable exceptions are in declaration, assignment, and output.

#include <span class="code-string">"lint.h"</span>

Points of Interest

Implementing the conditional testing was a real bugger. My implementation works, but I think there must be a better way to do it. There are additional things I'd like to do to the library as well.

  • Possibly implement faster multiplication and division algorithms using FFT, Barrett, or whatever.
  • Add capability to assign a value using a string in any radix from 2 to 36, not just base 10.
  • Make use of MMX and XMM registers for even faster inline assembly.


Initial releaseDecember 4, 2005by Jeremy A. Wilson 
UpdateDecember 6, 2005by Jeremy A. WilsonDiscovered my comparison operators were using the wrong assembly instruction which failed to report correctly if the MSB was set in one DWORD and not the other.
UpdateDecember 9, 2005by Jeremy A. WilsonAfter further review of my December 6th fix, I realized I still hadn't fixed it right. Now I have. I also ran a complete set of comparisons.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Jeremy A. Wilson
Software Developer
United States United States
I've worked in the industry since 1992. After the dot com crash of 2001, I went back to school and graduated from the University of North Texas in 2005. I now live in the Dallas area with my wife and two children, and work as a senior software engineer for a local company.

I first learned to program on a Commodore 64 when I was 12 years old. The rest is history...

You may also be interested in...


Comments and Discussions

Questionlint conversion to AnsiiString Pin
Member 108046863-Jun-15 13:37
memberMember 108046863-Jun-15 13:37 
Generalchar *lint::value(int radix) bug Pin
Mark Oliver26-Apr-11 17:25
memberMark Oliver26-Apr-11 17:25 
Hi, This version has special mods for my application plus a bug fix - necessary output left side '0' padding for multiple of 2 radixes. I used my IDE Embarcadero C++Builder XE Version 15.0.3953.35171 that has 64 bit unsigned longs.

char * lint::radix4Charset  =   "ADFT";
/* string conversion operator */
char *lint::value(int radix) {
	static lint divisor, quotient, remainder, temp;
	char output[ (LINT_LENGTH*32) + 1 ];
	char *str_temp;
	int next_char;
	bool is_negative = false;

	// deallocate any space previously given to the string
	if( str_value ) {
		delete [] str_value;
		str_value = 0;

	// throw an exception if radix is outside the range.  Proper use of
	// this exception can allow the caller to deallocate any memory allocated
	// previously by printing a value.
 //	if( (radix < 2) || (radix > 36) ) throw("Radix must be between 2 and 36.");

	temp.copy_from(*this);			// make a copy of this value since it will be destroyed

	output[0] = '\0';				// clear the string return value
	if( temp == 0 ) {				// if the value is zero, just return zero
		str_value = new char[2];
		str_value[0] = (radix == 62 ? radix62Charset[0] : '0');
		str_value[1] = '\0';
		return str_value;

	next_char = 0;					// set character position to begin writing digits
	int cpl = 64 / radix;

	switch( radix ) {				// use more efficient methods for powers of 2
		case 2:
		case 4:
		case 8:
		case 16:
		case 32:
			str_temp = new char[33];
			for( int i = 0; i < LINT_LENGTH; i++ ) {
				if( (next_char == 0) && (data[i] == 0) ) {
					// do nothing yet
				} else {
					itoa((unsigned long)data[i], str_temp, radix);
					int L = strlen(str_temp);
					if (L<cpl && next_char != 0) {
					if (radix4Charset != (char *)Null && radix==4)  // intelligent barcode
						for (int r4i = 0;r4i<(int)strlen(str_temp);r4i++)
								str_temp[r4i]=radix4Charset[str_temp[r4i] - '0'];
					strcat(output, str_temp);
					next_char = strlen(output);
			delete [] str_temp;
			if( (radix == 10)		// make the value positive if its negative and radix = 10
			&&  (([0] & 0x80000000) != 0)
			) {
				is_negative = true;

			divisor = radix;		// set our divisor
			while( temp != 0 ) {	// while temp has a value
				// calculate quotient and remainder
				div_mod_calculate(temp, divisor, quotient, remainder);
				// append string value of remainder digit to output string
				if (radix == 62)
					output[next_char++] = radix62Charset[[LAST_DWORD]];
				if (radix == 64)
					output[next_char++] = radix64Charset[[LAST_DWORD]];
				if([LAST_DWORD] < 10 ) {
					output[next_char++] = (char)('0' +[LAST_DWORD]);
				} else {
					output[next_char++] = (char)(55 +[LAST_DWORD]); // 55 = 'A' - 10
				temp = quotient;	// assign quotient to temp for next iteration

			if( is_negative )
				output[next_char++] = '-';	// end the return value with a minus sign

			output[next_char++] = '\0';		// null terminate the string
			strrev(output);					// reverse the characters in the string
	str_value = new char[ strlen(output) + 1 ];
	strncpy(str_value, output, strlen(output) + 1);

	return str_value;

GeneralGreat class, possible bug..... Pin
Ceri16-Aug-06 2:26
memberCeri16-Aug-06 2:26 
Questionxlint? Pin
OvermindDL125-Mar-06 19:05
memberOvermindDL125-Mar-06 19:05 
GeneralRegisters should be preserved Pin
GeertMys24-Jan-06 7:03
memberGeertMys24-Jan-06 7:03 
GeneralUnfortunately does not seem to work under MSVC Pin
lucchicoine20-Dec-05 13:14
memberlucchicoine20-Dec-05 13:14 
GeneralRe: Unfortunately does not seem to work under MSVC Pin
HobbitCoder21-Dec-05 13:07
memberHobbitCoder21-Dec-05 13:07 
GeneralRe: Unfortunately does not seem to work under MSVC Pin
Jeremy A. Wilson23-Dec-05 10:57
memberJeremy A. Wilson23-Dec-05 10:57 
QuestionRe: Unfortunately does not seem to work under MSVC Pin
Zsuzsi22-May-06 5:25
memberZsuzsi22-May-06 5:25 
GeneralConst correctness Pin
HobbitCoder17-Dec-05 10:37
memberHobbitCoder17-Dec-05 10:37 
GeneralRe: Const correctness Pin
Jeremy A. Wilson23-Dec-05 10:57
memberJeremy A. Wilson23-Dec-05 10:57 
JokeBUG Pin
kevincpp15-Dec-05 23:02
memberkevincpp15-Dec-05 23:02 
GeneralRe: BUG Pin
Jeremy A. Wilson16-Dec-05 22:37
memberJeremy A. Wilson16-Dec-05 22:37 
GeneralRe: BUG Pin
Toby Opferman20-Jan-06 8:20
memberToby Opferman20-Jan-06 8:20 
GeneralRe: BUG Pin
MadFalcon7-Jul-06 13:12
memberMadFalcon7-Jul-06 13:12 
QuestionRe: BUG Pin
Mohammed Hossny23-Aug-06 18:06
memberMohammed Hossny23-Aug-06 18:06 
GeneralNice Work! Pin
yafan15-Dec-05 11:51
memberyafan15-Dec-05 11:51 
Generala few comments Pin
Warren D Stevens15-Dec-05 9:49
memberWarren D Stevens15-Dec-05 9:49 
GeneralRe: a few comments Pin
Jeremy A. Wilson15-Dec-05 13:14
memberJeremy A. Wilson15-Dec-05 13:14 
Generalyou should change the name ... Pin
Maximilien15-Dec-05 8:06
memberMaximilien15-Dec-05 8:06 
GeneralRe: you should change the name ... Pin
Nishant Sivakumar15-Dec-05 9:47
staffNishant Sivakumar15-Dec-05 9:47 
GeneralRe: you should change the name ... Pin
Warren D Stevens15-Dec-05 9:50
memberWarren D Stevens15-Dec-05 9:50 
GeneralRe: you should change the name ... Pin
Harold Bamford15-Dec-05 11:05
memberHarold Bamford15-Dec-05 11:05 
GeneralRe: you should change the name ... Pin
Warren D Stevens15-Dec-05 11:37
memberWarren D Stevens15-Dec-05 11:37 
GeneralRe: you should change the name ... Pin
Jeremy A. Wilson15-Dec-05 13:23
memberJeremy A. Wilson15-Dec-05 13:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170217.1 | Last Updated 15 Dec 2005
Article Copyright 2005 by Jeremy A. Wilson
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid