Click here to Skip to main content
15,886,840 members
Articles / Programming Languages / C++

LINT: Large Integer Object Library

Rate me:
Please Sign up or sign in to vote.
4.59/5 (21 votes)
9 Dec 2005CPOL2 min read 91.6K   646   22   32
Lint is a signed large integer data type class library

Introduction

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.

Background

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 overloadable 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.

C++
#include "lint.h"
#include <stdio.h>

int main() {
    lint a = 1234;          // value assignment of a literal
    lint b = -5678;         // a lint is a signed integer data type
    lint c = a;             // assignment to another lint value
    lint d = "457639857304951675093650987359087";   	// use a string for those 
						// really BIG numbers
    lint e = "-563857365015613047563";	     // this works for negative values too
    
    lint x, y, z;
    x = d*e+a*b;            // math shouldn't be a problem.
    y = x/(e*e);
    
    // assignment to zero is the only ambiguous operation 
    // that you need to be specific on.
    z = (signed long)0;                                

    // the class allocates its own buffer to print a 
    // character representation of its value.
    // By default, it prints in base 10
    printf( "y base 10 = %s\n", z.value() );
    
    // You can print in another radix though - anything from 2 to 36
    printf( "y base 16 = %s\n", z.value(16) );
    printf( "y base 2 = %s\n", z.value(2) );
    
    // Internally, the memory for a lint is laid out going from 
    // MSB to LSB in an array of 32-bit DWORDs.
    // [2047th bit ... 1024th bit ... 0th bit]
    
    // If you need more or less than 2048 bit numbers, open lint.h
    // and redefine LINT_LENGTH
    
    // Lastly, the function call operator allows direct referential 
    // access to the DWORDs that comprise
    // a lint value.
    y(0) = 0x12345678;                  	// This sets the Most Significant 
					// DWORD to 0x12345678
    long my_bit_field = y(LAST_DWORD);  	// LAST_DWORD is a constant defined 
					// in the header file
    
    return 0;
}

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.

History

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
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...

Comments and Discussions

 
GeneralNot working ...Giving errors Pin
vijay_abcd5-Jul-07 1:17
vijay_abcd5-Jul-07 1:17 
Generalwrong Pin
jesusH5-Sep-06 21:56
jesusH5-Sep-06 21:56 
Generalwrong Pin
jesusH5-Sep-06 21:45
jesusH5-Sep-06 21:45 
GeneralWONDERFULL Pin
nachofiuba19-Jun-06 8:09
nachofiuba19-Jun-06 8:09 
GeneralDon't Post Here! We've moved... Pin
Jeremy A. Wilson15-Dec-05 11:59
Jeremy A. Wilson15-Dec-05 11:59 
QuestionCan not run on VC6.0 Pin
kevincpp13-Dec-05 23:49
kevincpp13-Dec-05 23:49 
AnswerRe: Can not run on VC6.0 Pin
Jeremy A. Wilson14-Dec-05 5:09
Jeremy A. Wilson14-Dec-05 5:09 
QuestionRe: Can not run on VC6.0 Pin
kevincpp14-Dec-05 13:18
kevincpp14-Dec-05 13:18 
AnswerRe: Can not run on VC6.0 Pin
Jeremy A. Wilson14-Dec-05 14:46
Jeremy A. Wilson14-Dec-05 14:46 
JokeRe: Can not run on VC6.0 Pin
kevincpp14-Dec-05 15:15
kevincpp14-Dec-05 15:15 
JokeRe: Can not run on VC6.0 Pin
kevincpp14-Dec-05 19:39
kevincpp14-Dec-05 19:39 
GeneralSome notes Pin
NickViz13-Dec-05 21:16
NickViz13-Dec-05 21:16 
GeneralRe: Some notes Pin
Jeremy A. Wilson14-Dec-05 5:21
Jeremy A. Wilson14-Dec-05 5:21 
GeneralOpen Source Pin
A name I made up.13-Dec-05 6:19
A name I made up.13-Dec-05 6:19 
GeneralRe: Open Source Pin
Jeremy A. Wilson13-Dec-05 17:11
Jeremy A. Wilson13-Dec-05 17:11 
Questionreal mathematic support ? Pin
toxcct12-Dec-05 21:28
toxcct12-Dec-05 21:28 
AnswerRe: real mathematic support ? Pin
yafan13-Dec-05 4:14
yafan13-Dec-05 4:14 
GeneralRe: real mathematic support ? Pin
toxcct13-Dec-05 4:17
toxcct13-Dec-05 4:17 
GeneralBigInteger in the J# library Pin
Ashaman12-Dec-05 3:37
Ashaman12-Dec-05 3:37 
GeneralRe: BigInteger in the J# library Pin
Jeremy A. Wilson12-Dec-05 18:41
Jeremy A. Wilson12-Dec-05 18:41 
Generalsorry but Pin
echo zulu11-Dec-05 9:54
echo zulu11-Dec-05 9:54 
GeneralRe: sorry but Pin
Jeremy A. Wilson11-Dec-05 10:31
Jeremy A. Wilson11-Dec-05 10:31 
I am aware of the lint tool that programmers use to check their "C" code, but to my knowledge, this tool is not used to check "C++" code. The languages, while similar for obvious reasons, are in fact, remarkably different. I could be wrong however - its been years since I used any tools outside the standard tools available in the IDE for VC++.

I would also like to point out that many words in any given language have been used to name completely different things. Smile | :) Recognizing that I was giving an old name to a new thing, I chose to qualify my title with a colon and short description so as to eliminate confusion for someone doing a web search.

Now you have me curious though. My use of the word actually makes sense. I wonder how the original authors of lint came up with that name for their code analysis and profiling tool.

Jeremy Wilson
mitselplik@cox.net
GeneralRe: sorry but Pin
Ravi Bhavnani11-Dec-05 17:18
professionalRavi Bhavnani11-Dec-05 17:18 
GeneralRe: sorry but Pin
Ashaman12-Dec-05 3:31
Ashaman12-Dec-05 3:31 
GeneralRe: sorry but Pin
Matt Brunk11-Dec-05 21:20
Matt Brunk11-Dec-05 21:20 

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.