Click here to Skip to main content
15,898,134 members
Articles / Programming Languages / Objective C

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 93.7K   417   23  
Lint is a signed large integer data type class library
/* 
	LINT - Large INTeger object library.
	Copyright (C) 2005 Jeremy A. Wilson 

	Licensed under the GNU Lesser General Public License version 2.1

	This library is free software; you can redistribute it and/or modify it under the terms 
	of the GNU Lesser General Public License as published by the Free Software Foundation; 
	either version 2.1 of the License, or (at your option) any later version.

	This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
	See the GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License along with this 
	library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
	Boston, MA 02111-1307 USA 

	Author Information:
		Jeremy A. Wilson
		email: mitselplik@cox.net
		address: 915 Dover Dr., Gainesville, TX 76240
*/
#if !defined(_LINT_)
#define _LINT_

#if !defined(LINT_LENGTH)
#define LINT_LENGTH 64		// the number of 32-bit DWORDS to use - default 64 results in 2048 bit integers
#endif

class lint {
	long data[LINT_LENGTH];		
	char *str_value;

	void copy_from(lint&);
	void from_string(const char *);
	friend void div_mod_calculate(lint&, lint&, lint&, lint&);
	void not();
	void negate();
public:
	lint();
	lint(lint&);
	lint(signed long);
	lint::lint(const char *);
	lint(long *, unsigned int);
	~lint();

	lint& operator=(lint&);
	lint& operator=(signed long);
	lint& operator=(const char *);

	lint& operator++();
	lint& operator++(int);
	lint& operator--();
	lint& operator--(int);
	lint& operator~();
	lint& operator-();
	bool operator!();
	
	lint& operator+=(signed long);
	lint& operator+=(lint&);
	lint& operator-=(signed long);
	lint& operator-=(lint&);
	lint& operator*=(signed long);
	lint& operator*=(lint&);
	lint& operator/=(signed long);
	lint& operator/=(lint&);
	lint& operator%=(signed long);
	lint& operator%=(lint&);
	lint& operator<<=(signed long);
	lint& operator<<=(lint&);
	lint& operator>>=(signed long);
	lint& operator>>=(lint&);

	lint& operator&=(unsigned long);
	lint& operator&=(lint&);
	lint& operator|=(unsigned long);
	lint& operator|=(lint&);
	lint& operator^=(unsigned long);
	lint& operator^=(lint&);

	char *value(int radix = 10);
	signed long& operator()(unsigned);

	friend lint& operator+(lint&, signed long);
	friend lint& operator+(long, lint&);
	friend lint& operator+(lint&, lint&);
	
	friend lint& operator-(lint&, signed long);
	friend lint& operator-(signed long, lint&);
	friend lint& operator-(lint&, lint&);

	friend lint& operator<<(lint&, signed long);
	friend lint& operator<<(lint&, lint&);

	friend lint& operator>>(lint&, signed long);
	friend lint& operator>>(lint&, lint&);

	friend lint& operator*(lint&, signed long);
	friend lint& operator*(signed long, lint&);
	friend lint& operator*(lint&, lint&);
	
	friend lint& operator/(lint&, signed long);
	friend lint& operator/(signed long, lint&);
	friend lint& operator/(lint&, lint&);
	
	friend lint& operator%(lint&, signed long);
	friend lint& operator%(lint&, lint&);
		
	friend bool operator==(lint&, signed long);
	friend bool operator==(signed long, lint&);
	friend bool operator==(lint&, lint&);
	
	friend bool operator!=(lint&, signed long);
	friend bool operator!=(signed long, lint&);
	friend bool operator!=(lint&, lint&);
	
	friend bool operator<(lint&, lint&);
	friend bool operator<(lint&, signed long);
	friend bool operator<(signed long, lint&);

	friend bool operator<=(lint&, lint&);
	friend bool operator<=(lint&, signed long);
	friend bool operator<=(signed long, lint&);

	friend bool operator>(lint&, lint&);
	friend bool operator>(lint&, signed long);
	friend bool operator>(signed long, lint&);

	friend bool operator>=(lint&, lint&);
	friend bool operator>=(lint&, signed long);
	friend bool operator>=(signed long, lint&);

	friend lint& operator&(lint&, unsigned long);
	friend lint& operator&(unsigned long, lint&);
	friend lint& operator&(lint&, lint&);

	friend lint& operator|(lint&, unsigned long);
	friend lint& operator|(unsigned long, lint&);
	friend lint& operator|(lint&, lint&);

	friend lint& operator^(lint&, unsigned long);
	friend lint& operator^(unsigned long, lint&);
	friend lint& operator^(lint&, lint&);
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


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