Comparing two long numbers

R

ruds

hello,
I want to compare 2 long numbers.The i/p number i have to compare it
with 30000000000.
but i get an error saying: "integer nuber too large: 30000000000
if(a<30000000000)
^
what should i do?
 
M

Mark Thornton

RedGrittyBrick said:
Use a long constant.
if(a<3000000000l)

I prefer to use a capital 'L' to designate long constants as it is more
readily distinguished from the numeral 1. So

if(a<3000000000L)

Mark Thornton
 
L

Lasse Reichstein Nielsen

RedGrittyBrick said:
ruds wrote: ....

Use a long constant.
if(a<3000000000l)

True. And on top of that, I (and several style guides) recommend that
you finish a long literal with an upper-case L, not lower-case, since
that is too easily read as the digit "one" ("1") in many fonts. I.e.
if (a < 3000000000L)
/L
 
J

John B. Matthews

Patricia Shanahan said:
I suggest using "L" instead of "l". In some fonts, "l" can be difficult
to distinguish from "1".

Patricia

Similarly, I usually use "d" instead of "D" for double. The latter looks
too much like a "0" in some fonts.

John
 
A

Arne Vajhøj

Lew said:
Why do you use either "d" or "D"? Is it something you always put on
double constants, or just for potentially ambiguous situations? If the
latter, how do you assess ambiguity?

Or to put it more direct: 12.34 is a double without d or D.

In Fortran a d0 is necessary to make it a double, but ...

Arne
 
M

Mark Space

Arne said:
In Fortran a d0 is necessary to make it a double, but ...

And I think the same in C, right?

double n = 1.5d;

So he probably uses "d" out of habit or for folks who commonly switch
between Java and other languages. No chance of getting it wrong for a
given language if you just always get in the habit of adding it.
 
A

Arne Vajhøj

Mark said:
And I think the same in C, right?

double n = 1.5d;

So he probably uses "d" out of habit or for folks who commonly switch
between Java and other languages. No chance of getting it wrong for a
given language if you just always get in the habit of adding it.

I am pretty sure that C also has default double and explicit f
for float.

Arne
 
J

John B. Matthews

Lew said:
Why do you use either "d" or "D"? Is it something you always put on double
constants, or just for potentially ambiguous situations? If the latter, how
do you assess ambiguity?

I don't use either "d" or "D"; I use "d", but I have to read other
people's "D"s. Presbyopia comes to us all. :)

Regarding ambiguity, would you consider a fully parenthesized infix
expression less ambiguous than one that relied on the implied precedence
rules? Which is easier verify by inspection? In the same sense, a bare
constant in an expression relies on the implied promotion rules. The
goal is to clarify intent. In the present case the compiler required it.
After that, the choice of "d" v. "D" or "l" v. "L" is simply one of
legibility.

John
 
D

Daniele Futtorovic

Most people don't bother with either "d" or "D" in Java double
constants. I never have to read other people's "D" in Java code; I
don't think I've ever encountered a double suffix on a constant in any
professional Java code.

double athird = 1d / 3; ?

Granted, "1." would be the same. But haven't you ever encountered it?
 
J

John B. Matthews

Lew said:
Most people don't bother with either "d" or "D" in Java double constants. I
never have to read other people's "D" in Java code; I don't think I've ever
encountered a double suffix on a constant in any professional Java code.


The compiler does not require a "d" suffix. By itself, 1.0 is a double
constant in Java.
<http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.2>

No doubt, but consider a rational constant. I slightly prefer the
second. You?

private static final double ASPECT_RATIO = 0.7;
private static final double ASPECT_RATIO = 7d / 10;
private static final double ASPECT_RATIO = 7.0 / 10.0;
The choice of "d" vs. not using a suffix at all is my question. From your
answer, I gather you are under the misapprehension that it's required.

In the original example, it surely was! But thank you for considering my
potential misapprehension:)

John
 
J

John B. Matthews

Daniele Futtorovic said:
double athird = 1d / 3; ?

Granted, "1." would be the same. But haven't you ever encountered it?

Yes! Using "1d / 3" is especially apropos to calling attention to the
(approximately) rational character of the expression.

John
 
D

Daniele Futtorovic

Urgh. Now this:

double farthing = 1d / 4 ;

is at least numismatically accurate, but won't compile after 1960!

Yet more puzzling:

single farthing = 1p / 4 ;

But it won't compile at all!! Sheesh. I wonder who's designing those
"computer language" things.
 
N

Nigel Wade

It should compile, but it ought to throw a IllegalTenderException for dates
after 1960.
Yet more puzzling:

single farthing = 1p / 4 ;

But it won't compile at all!!

That statement is both semantically and chronologically incorrect. Hardly
surprising it won't compile.

A farthing was not equal to 1p/4, nor could ever have been 1p/4. The farthing
was retired (1960) long before decimalisation when the new penny came into
circulation (1971). It was, as Tom said, equal to 1d/4.
 
D

Daniele Futtorovic

That statement is both semantically and chronologically incorrect. Hardly
surprising it won't compile.

A farthing was not equal to 1p/4, nor could ever have been 1p/4. The farthing
was retired (1960) long before decimalisation when the new penny came into
circulation (1971). It was, as Tom said, equal to 1d/4.

Ah, right, the old abbreviation for pence was "d". Damn.

But one quarter is 1/4: decimalisation don't enter into it. Not unless
you state 1/4 = 0.25.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top