Is long long standard?

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
BiK
Experienced poster
Posts: 104
Joined: Tue Sep 23, 2003 5:49 pm

Is long long standard?

Post by BiK »

During the last online conest there was a problem with input numbers that could be as big as 64 bits. Since long is only 32 bits I thought that I might use long long. I'd just read about it in a message on the board a few days ago. My compiler recognized it but I had problems when I wanted to perform mathematical operations (namely log and pow) on such long long numbers. The results were incorrect and the compiler was producing warning messages.

Example:
[cpp]long long m = (long long)log((double)n)/log(3.0)[/cpp]

Could anyone tell me whether long long is included in the standartd or not? And how can I avoid the problems with the math ops? Do you know some online stuff that could be helpfull on the topic?
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

As far as UVA judge goes, long long is pretty much standard.
Although i never found it being mentioned in any C++ books, UVA compiler supports it.

Since the math fucntions are only defined for the double data type, it is recommended that you do not use them in your programs handling long long data type.
Per
A great helper
Posts: 429
Joined: Fri Nov 29, 2002 11:27 pm
Location: Sweden

Post by Per »

It is part of the standard since C99.

Before that, it was just a GNU extension.

If you just want floor/ceil of the logarithm (which seems to be the case here), you can do something like this (for floor(log_3(n)))
[cpp]int m = 0, p = 1;
while ((p *= 3) <= n) ++m;[/cpp]
But you'll have to be really careful about overflow when n is nearly maximal (these troubles are left as an exercise). A replacement for pow is also simple.
Post Reply

Return to “C++”