473,395 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

large numbers

I was just wondering if there is anything in C++ similar to commas for
making large numbers more readable.

For instance, if you want to write one hundred million, the standard
way is 100000000, and it's
not immediately obvious how many zeros are there. I'd like to be able
to do something like:

long x = 100,000,000;

Any help is appreciated.

Jul 6 '07 #1
8 1349
mi******@gmail.com wrote:
I was just wondering if there is anything in C++ similar to commas for
making large numbers more readable.
No, unfortunately nothing. There was some talk about using the underscore
as the separator, but I don't think it reached the Committee. Ask about
the form '100_000_000' in 'comp.std.c++' to see whether it has ever been
suggested.
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 6 '07 #2
mi******@gmail.com wrote:
I was just wondering if there is anything in C++ similar to commas for
making large numbers more readable.

For instance, if you want to write one hundred million, the standard
way is 100000000, and it's
not immediately obvious how many zeros are there. I'd like to be able
to do something like:

long x = 100,000,000;

Any help is appreciated.
template <long M, unsigned E>
struct power {
static long value = M * power<E-1>::value;
};
template <long M>
struct power<M, 0{
static long value = 1;
};

....
long x = power<10, 8>::value;

or

#define e8 100##000##000
long x = e8;
#undef e8

--
rbh
Jul 6 '07 #3
Robert Bauck Hamar wrote:
mi******@gmail.com wrote:
>I was just wondering if there is anything in C++ similar to commas for
making large numbers more readable.

For instance, if you want to write one hundred million, the standard
way is 100000000, and it's
not immediately obvious how many zeros are there. I'd like to be able
to do something like:

long x = 100,000,000;

Any help is appreciated.

template <long M, unsigned E>
struct power {
static long value = M * power<E-1>::value;
static long value = M * power<M, E-1>::value;
};
template <long M>
struct power<M, 0{
static long value = 1;
};

...
long x = power<10, 8>::value;

or

#define e8 100##000##000
long x = e8;
#undef e8
--
rbh
Jul 6 '07 #4
mi******@gmail.com wrote:
I was just wondering if there is anything in C++ similar to commas for
making large numbers more readable.

For instance, if you want to write one hundred million, the standard
way is 100000000, and it's not immediately obvious how many zeros are
there. I'd like to be able to do something like:

long x = 100,000,000;

Any help is appreciated.
Why not just:

long x = 100 * 1000 * 1000;

Or even

static const long million = 1000 * 1000;
long x = 100 * million;

Jul 8 '07 #5
Robert Bauck Hamar wrote:
#define e8 100##000##000
I wouldn't call that "readable"... ;)
Jul 8 '07 #6
Rolf Magnus wrote:
mi******@gmail.com wrote:
>I was just wondering if there is anything in C++ similar to commas
for making large numbers more readable.

For instance, if you want to write one hundred million, the standard
way is 100000000, and it's not immediately obvious how many zeros are
there. I'd like to be able to do something like:

long x = 100,000,000;

Any help is appreciated.

Why not just:

long x = 100 * 1000 * 1000;
Are you sure it's guaranteed to work and not overflow or something of
that nature? Both 100 and 1000 are below the minimal 'int' limit, but
'100 * 1000' is beyond it. The compiler may be smart enough to make
sure the result is of the "next bigger type", but I can't find any
requirement to that effect in the Standard.
Or even

static const long million = 1000 * 1000;
long x = 100 * million;
That's better, since 'million' has a particular type.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 9 '07 #7
Victor Bazarov wrote:
Rolf Magnus wrote:
>mi******@gmail.com wrote:
>>I was just wondering if there is anything in C++ similar to commas
for making large numbers more readable.

For instance, if you want to write one hundred million, the standard
way is 100000000, and it's not immediately obvious how many zeros are
there. I'd like to be able to do something like:

long x = 100,000,000;

Any help is appreciated.

Why not just:

long x = 100 * 1000 * 1000;

Are you sure it's guaranteed to work and not overflow or something of
that nature?
Now that you mention it...
Both 100 and 1000 are below the minimal 'int' limit, but
'100 * 1000' is beyond it. The compiler may be smart enough to make
sure the result is of the "next bigger type", but I can't find any
requirement to that effect in the Standard.
Yes, you are right.
>
>Or even

static const long million = 1000 * 1000;
long x = 100 * million;

That's better, since 'million' has a particular type.
I think it can still overflow though, because 1000 has type int, so the
result of the multiplication will also be be int. The conversion to long
happens afterwards. So better make it:

static const long million = 1000L * 1000L;

Jul 9 '07 #8
On Fri, 06 Jul 2007 13:36:45 -0700, mi******@gmail.com wrote:
long x = 100,000,000;
long x = (long) 1E8;

--
Joel Yliluoma - http://iki.fi/bisqwit/
: comprehension = 1 / (2 ^ precision)
Jul 23 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Tuvas | last post by:
I've been thinking about writing a program to generate the world's largest prime numbers, just for the fun of it. This would require being able to hold an 8000000 digit number into memory (25...
18
by: Brad | last post by:
I have a problem in that I need to change a large decimal value into its hex equivalent. The largest decimal value I need to represent as hex is 25516777215. The problem here is that this number...
18
by: Zero | last post by:
Hi, I am calculating an integer to the pwer of a large integer, e.g. 2^5000. It turns out that the result I always get is zero. I am sure that the result is too large to store in such type...
22
by: Frinton | last post by:
Hi, I am trying to do some calculations on large numbers (ie 7,768,489,957,892,578,474,792,094 / 12,280) and no matter what I do it doesn't get it quite right. Its always somewhere between 10...
3
by: CFonville | last post by:
I was wondering if there is any way to store large numbers in a variable? With this simple script: var bigpi = 1234567890123456789012345678901234567890123456789012345678901234567890;...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.