Click here to Skip to main content
15,063,183 members
Articles / Programming Languages / Objective C
Posted 15 Dec 2005


23 bookmarked

Lint: Large Integer Object Library

Rate me:
Please Sign up or sign in to vote.
4.26/5 (10 votes)
15 Dec 20052 min read
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 "lint.h"
#include <stdio.h>

int main() {
    // value assignment of a literal
    lint a = 1234;
    // a lint is a signed integer data type
    lint b = -5678;
    // assignment to another lint value
    lint c = a;
    // use a string for those really BIG numbers
    lint d = "457639857304951675093650987359087";
    // this works for negative values too
    lint e = "-563857365015613047563";
    lint x, y, z;
    // math shouldn't be a problem.
    x = d*e+a*b;
    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.
    // This sets the Most Significant DWORD to 0x12345678
    y(0) = 0x12345678;
    // LAST_DWORD is a constant defined in the header file
    long my_bit_field = y(LAST_DWORD);
    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


Initial release December 4, 2005 by Jeremy A. Wilson  
Update December 6, 2005 by Jeremy A. Wilson Discovered 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.
Update December 9, 2005 by Jeremy A. Wilson After 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...

Comments and Discussions

Questionlint conversion to AnsiiString Pin
Member 108046863-Jun-15 12:37
MemberMember 108046863-Jun-15 12:37 
Generalchar *lint::value(int radix) bug Pin
Mark Oliver26-Apr-11 16:25
MemberMark Oliver26-Apr-11 16:25 
GeneralGreat class, possible bug..... Pin
Ceri16-Aug-06 1:26
MemberCeri16-Aug-06 1:26 
Questionxlint? Pin
OvermindDL125-Mar-06 18:05
MemberOvermindDL125-Mar-06 18:05 
GeneralRegisters should be preserved Pin
GeertMys24-Jan-06 6:03
MemberGeertMys24-Jan-06 6:03 
GeneralUnfortunately does not seem to work under MSVC Pin
lucchicoine20-Dec-05 12:14
Memberlucchicoine20-Dec-05 12:14 
GeneralRe: Unfortunately does not seem to work under MSVC Pin
HobbitCoder21-Dec-05 12:07
MemberHobbitCoder21-Dec-05 12:07 
GeneralRe: Unfortunately does not seem to work under MSVC Pin
Jeremy A. Wilson23-Dec-05 9:57
MemberJeremy A. Wilson23-Dec-05 9:57 
QuestionRe: Unfortunately does not seem to work under MSVC Pin
Zsuzsi22-May-06 4:25
MemberZsuzsi22-May-06 4:25 
GeneralConst correctness Pin
HobbitCoder17-Dec-05 9:37
MemberHobbitCoder17-Dec-05 9:37 
GeneralRe: Const correctness Pin
Jeremy A. Wilson23-Dec-05 9:57
MemberJeremy A. Wilson23-Dec-05 9:57 
JokeBUG Pin
kevincpp15-Dec-05 22:02
Memberkevincpp15-Dec-05 22:02 
GeneralRe: BUG Pin
Jeremy A. Wilson16-Dec-05 21:37
MemberJeremy A. Wilson16-Dec-05 21:37 
GeneralRe: BUG Pin
Toby Opferman20-Jan-06 7:20
MemberToby Opferman20-Jan-06 7:20 
GeneralRe: BUG Pin
MadFalcon7-Jul-06 12:12
MemberMadFalcon7-Jul-06 12:12 
QuestionRe: BUG Pin
Mo Hossny23-Aug-06 17:06
MemberMo Hossny23-Aug-06 17:06 
GeneralNice Work! Pin
yafan15-Dec-05 10:51
Memberyafan15-Dec-05 10:51 
Generala few comments Pin
Warren Stevens15-Dec-05 8:49
MemberWarren Stevens15-Dec-05 8:49 
GeneralRe: a few comments Pin
Jeremy A. Wilson15-Dec-05 12:14
MemberJeremy A. Wilson15-Dec-05 12:14 
Generalyou should change the name ... Pin
Maximilien15-Dec-05 7:06
MemberMaximilien15-Dec-05 7:06 
GeneralRe: you should change the name ... Pin
Nish Nishant15-Dec-05 8:47
sitebuilderNish Nishant15-Dec-05 8:47 
GeneralRe: you should change the name ... Pin
Warren Stevens15-Dec-05 8:50
MemberWarren Stevens15-Dec-05 8:50 
GeneralRe: you should change the name ... Pin
Harold Bamford15-Dec-05 10:05
MemberHarold Bamford15-Dec-05 10:05 
GeneralRe: you should change the name ... Pin
Warren Stevens15-Dec-05 10:37
MemberWarren Stevens15-Dec-05 10:37 
GeneralRe: you should change the name ... Pin
Jeremy A. Wilson15-Dec-05 12:23
MemberJeremy A. Wilson15-Dec-05 12: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.