• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Robert James Saunders

Beyond 4294967295

16 posts in this topic

Is there a way to make this number larger using the "int" besides "long int"

 

So lets say I want an unlimited number (which ill never use). More curious then anything.
 

 

#include <iostream>
using namespace std;
 
int main()
{
    //integer wrap around
    score = 4294967295;
    cout << "score: " << score << endl;
 
    ++score;
    cout << "score: " << score << endl;
 
    return 0;
}
 
So instead of making this number wrap around keep going up and up?
0

Share this post


Link to post
Share on other sites

Or you can easily implement your own big int library. It is really easy task. Last year, when I was 9th grade one of the problem we needed to solve in our local programming competition was:

Without use of any other libraries(ohh they gave us one of the first borland compilers... C++ without namespaces. I was shocked then) we had to find the 1000th fibonacci and check if it can be evenly divided by another number, taken from the standart input.

 

So if this can be a task for 9th graders it should be easy...

 

What I did: array of chars which were dinamically allocated and used some loops to do basic operations. Also..You are free to overload operators like << to print directly.

0

Share this post


Link to post
Share on other sites

If you use __int64 your max number now becomes 18.446.744.073.709.551.615 which is pretty large. If you need more than that (or an arbitrary representation until you've exhausted RAM), you'll have to use a big num library

1

Share this post


Link to post
Share on other sites

'int' doesn't hold 4294967295, 'unsigned int' does, int is signed by default and only holds 2147483647. (assuming the int is 32 bit - which isn't guaranteed  but likely).
 
If you include the standard header <cstdint>, C++ defines alot of integer types that are more specific:
int8_t = -127 to +127
uint8_t = 0 to 255
 
int16_t = -32,767 to +32,767 (32 thousand negative or positive)
uint16_t = 0 to 65,536 (65 thousand)
 
int32_t = -2,147,483,647 to +2,147,483,647    (two billion negative or positive)
uint32_t = 0 to 4,294,967,295  (4 billion)

int64_t = -9,223,372,036,854,775,807 to +9,223,372,036,854,775,807 (nine Quintillion negative or positive)
uint64_t = 0 to 18,446,744,073,709,551,615 (18 Quintillion)
 
If you need higher that 18 quintillion, you have to use a third-party library or roll your own, and it won't be as optimized.

 

My suggestions:

 

By default, use 'int' if you need a signed number, and 'unsigned int' (or just 'unsigned'; it means the same) if you need an unsigned number. These will be the best optimized.

If you actually need 32 bits, and not just a large number in general, use int32_t or uint32_t - they will be self-documenting your intent.

 

If you need to conserve memory, only then go lower to 16 bit or 8 bit integers - they can be slightly slower, but not something you'll notice. (Don't preoptimize, but have the knowledge).

If you need a larger number, use a 64 bit int.

If you need a extremely large number - use a BIGNUM class.

Edited by Servant of the Lord
2

Share this post


Link to post
Share on other sites

If you include the standard header , C++ defines alot of integer types that are more specific:
int8_t = -127 to +127

 

Actually int8_t is =-128 to 127 

uint8_t = 0 to 255
 
int16_t = -32,768 to +32,767 (32 thousand negative or positive)
uint16_t = 0 to 65,536 (65 thousand)
 
int32_t = -2,147,483,648 to +2,147,483,647    (two billion negative or positive)
uint32_t = 0 to 4,294,967,295  (4 billion)

int64_t = -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 (nine Quintillion negative or positive)
uint64_t = 0 to 18,446,744,073,709,551,615 (18 Quintillion)

Edited by BornToCode
2

Share this post


Link to post
Share on other sites
I wrote my own C++ bigint libraries. In fact I wrote three of them, one of which is used in a couple of commercial products, and has had extremely rigorous testing.
Bigint: for integers of a fixed (templated) size e.g. 512 bits, and comes in a signed and an unsigned variety.
VarBigInt: is for integers of a size that varies at runtime.
StringInt: holds integers as a string, for when displaying the value is more common than doing maths on it.

They're on my homepage here if you're curious to see how they are done: http://homepages.ihug.co.nz/~aurora76/Malc/Useful_Classes.htm
Be prepared to learn a lot about operator overloading if you look at them smile.png

There are limitations imposed by the C++ language mind you, in that you can't specifiy large numbers as you would normally do. Instead the typical thing for these libraries to do is to allow you to specify the value as a string. Other than that, they work pretty much like any other integral type.
1

Share this post


Link to post
Share on other sites


There are limitations imposed by the C++ language mind you, in that you can't specifiy large numbers as you would normally do. Instead the typical thing for these libraries to do is to allow you to specify the value as a string. Other than that, they work pretty much like any other integral type.

In C++11 you can use user defined literals for this.
1

Share this post


Link to post
Share on other sites

If you include the standard header , C++ defines alot of integer types that are more specific:
int8_t = -127 to +127

 

Actually int8_t is =-128 to 127 

 

Whoops, you're right. No point wasting a space for -0 is there? laugh.png

0

Share this post


Link to post
Share on other sites

 

If you include the standard header , C++ defines alot of integer types that are more specific:
int8_t = -127 to +127

 

Actually int8_t is =-128 to 127 

 

Whoops, you're right. No point wasting a space for -0 is there? laugh.png

Having a negative zero could also introduce the need for different hardware paths for signed and unsigned arithmetic. One major advantage of two's complement notation is that signed and unsigned are exactly the same at hardware level. For addition, subtraction, and multiplication, anyway.

1

Share this post


Link to post
Share on other sites
It depends on your platform's negative number representation. Most modern machine will use 2's complement which will go from -128 to 127, but neither C nor C++ guarantee it. The C standard's SCHAR_MIN is listed as -127 not -128.
0

Share this post


Link to post
Share on other sites

If you include the standard header , C++ defines alot of integer types that are more specific:
int8_t = -127 to +127

Actually int8_t is =-128 to 127

As has been mentioned, on two's complement architectures, yes. 1's complement architectures do exist (although more "did"), having the advantage of slightly simpler circuitry. For practical purposes, nowadays, on commodity hardware, one generally assumes two's complement.

Edited by Geometrian
0

Share this post


Link to post
Share on other sites

There are limitations imposed by the C++ language mind you, in that you can't specifiy large numbers as you would normally do. Instead the typical thing for these libraries to do is to allow you to specify the value as a string. Other than that, they work pretty much like any other integral type.

In C++11 you can use user defined literals for this.
Yeah I'd read about those not long ago thanks. I'll try it out next time I have a compatible compiler installed.
0

Share this post


Link to post
Share on other sites

It depends on your platform's negative number representation. Most modern machine will use 2's complement which will go from -128 to 127, but neither C nor C++ guarantee it. The C standard's SCHAR_MIN is listed as -127 not -128.



If you include the standard header , C++ defines alot of integer types that are more specific:
int8_t = -127 to +127

Actually int8_t is =-128 to 127


As has been mentioned, on two's complement architectures, yes. 1's complement architectures do exist (although more "did"), having the advantage of slightly simpler circuitry. For practical purposes, nowadays, on commodity hardware, one generally assumes two's complement.


No, int8_t is 2's complement with no padding bits.
 
Servant of the Lord explicitly mentioned (and was corrected by BornToCode) using the u/intN_t types. The C standard states (which the C++ standard references in section 18.4.1 and requires to be compliant with the C standard):
 

7.20.1.1 Exact-width integer types
1 The typedef name intN_t designates a signed integer type with width N, no padding
bits, and a two’s complement representation. Thus, int8_t denotes such a signed
integer type with a width of exactly 8 bits.
2 The typedef name uintN_t designates an unsigned integer type with width N and no
padding bits. Thus, uint24_t denotes such an unsigned integer type with a width of
exactly 24 bits.
3 These types are optional. However, if an implementation provides integer types with
widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a
two’s complement representation, it shall de?ne the corresponding typedef names.

 
That is, these data types are required to be the specified number of bits in 2's complement representation. Section 7.20.2.1 confirms the ranges:
 

7.20.2.1 Limits of exact-width integer types
1 — minimum values of exact-width signed integer types
INTN_MIN exactly ?(2N?1)
— maximum values of exact-width signed integer types
INTN_MAX exactly 2N?1? 1
— maximum values of exact-width unsigned integer types
UINTN_MAX exactly 2N? 1

 
You are, of course, correct in that non-exact width integer types (like char, short, int, etc.) may not be 2's complement (and of course, the macros giving the min and max values for each type take this into account like you note with SCHAR_MIN/MAX). Edited by Cornstalks
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0