Comparing two long numbers  
Author Message
Tom Anderson





PostPosted: 2008-6-2 23:18:00 Top

java-programmer, Comparing two long numbers On Mon, 2 Jun 2008, Daniele Futtorovic wrote:

> On 2008-06-02 13:22 +0100, Lew allegedly wrote:
>> Lew wrote:
>>>> 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?
>>
>> John B. Matthews wrote:
>>> 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. :-)
>>
>> 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; ?

Urgh. Now this:

double farthing = 1d / 4 ;

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

tom

--
Eat whip you steroid wall-bashing lug-head! -- The Laird
 
Tom Anderson





PostPosted: 2008-6-2 23:18:00 Top

java-programmer >> Comparing two long numbers On Mon, 2 Jun 2008, Daniele Futtorovic wrote:

> On 2008-06-02 13:22 +0100, Lew allegedly wrote:
>> Lew wrote:
>>>> 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?
>>
>> John B. Matthews wrote:
>>> 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. :-)
>>
>> 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; ?

Urgh. Now this:

double farthing = 1d / 4 ;

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

tom

--
Eat whip you steroid wall-bashing lug-head! -- The Laird
 
Daniele Futtorovic





PostPosted: 2008-6-2 23:31:00 Top

java-programmer >> Comparing two long numbers On 2008-06-02 17:17 +0100, Tom Anderson allegedly wrote:
> On Mon, 2 Jun 2008, Daniele Futtorovic wrote:
>> double athird = 1d / 3; ?
>
> 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.

--
DF.
to reply privately, change the top-level domain
in the FROM address from "invalid" to "net"
 
 
Nigel Wade





PostPosted: 2008-6-2 23:58:00 Top

java-programmer >> Comparing two long numbers Daniele Futtorovic wrote:

> On 2008-06-02 17:17 +0100, Tom Anderson allegedly wrote:
>> On Mon, 2 Jun 2008, Daniele Futtorovic wrote:
>>> double athird = 1d / 3; ?
>>
>> Urgh. Now this:
>>
>> double farthing = 1d / 4 ;
>>
>> is at least numismatically accurate, but won't compile after 1960!

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.

--
Nigel Wade
 
 
Daniele Futtorovic





PostPosted: 2008-6-3 0:20:00 Top

java-programmer >> Comparing two long numbers On 2008-06-02 17:58 +0100, Nigel Wade allegedly wrote:
> Daniele Futtorovic wrote:
>> 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.

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.

--
DF.
to reply privately, change the top-level domain
in the FROM address from "invalid" to "net"
 
 
Daniel Pitts





PostPosted: 2008-6-3 0:34:00 Top

java-programmer >> Comparing two long numbers Arne Vajh酶j wrote:
> Mark Space wrote:
>> Arne Vajh酶j wrote:
>>> 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.
>
> I am pretty sure that C also has default double and explicit f
> for float.
>
> Arne
I believe 1.5d is a compiler error in C.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
 
 
Tom Anderson





PostPosted: 2008-6-3 0:53:00 Top

java-programmer >> Comparing two long numbers On Mon, 2 Jun 2008, Daniele Futtorovic wrote:

> On 2008-06-02 17:58 +0100, Nigel Wade allegedly wrote:
>> Daniele Futtorovic wrote:
>>> 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.
>
> 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.

The point is that on decimalisation, the letter for 'penny' changed (as
did the value of the coin) - the pre-decimal penny is d, the decimal penny
is p. 1p/4 would be a quarter of a decimal penny, a denomination which has
never existed.

tom

--
Eat whip you steroid wall-bashing lug-head! -- The Laird
 
 
Daniele Futtorovic





PostPosted: 2008-6-3 1:16:00 Top

java-programmer >> Comparing two long numbers On 2008-06-02 18:52 +0100, Tom Anderson allegedly wrote:
> On Mon, 2 Jun 2008, Daniele Futtorovic wrote:
>
>> On 2008-06-02 17:58 +0100, Nigel Wade allegedly wrote:
>>> Daniele Futtorovic wrote:
>>>> 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.
>>
>> 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.
>
> The point is that on decimalisation, the letter for 'penny' changed (as
> did the value of the coin) - the pre-decimal penny is d, the decimal
> penny is p. 1p/4 would be a quarter of a decimal penny, a denomination
> which has never existed.

I see. Thanks for the clarification.

--
DF.
to reply privately, change the top-level domain
in the FROM address from "invalid" to "net"
 
 
Lew





PostPosted: 2008-6-3 8:01:00 Top

java-programmer >> Comparing two long numbers Daniele Futtorovic wrote:
> On 2008-06-02 18:52 +0100, Tom Anderson allegedly wrote:
>> On Mon, 2 Jun 2008, Daniele Futtorovic wrote:
>>
>>> On 2008-06-02 17:58 +0100, Nigel Wade allegedly wrote:
>>>> Daniele Futtorovic wrote:
>>>>> 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.
>>>
>>> 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.
>>
>> The point is that on decimalisation, the letter for 'penny' changed
>> (as did the value of the coin) - the pre-decimal penny is d, the
>> decimal penny is p. 1p/4 would be a quarter of a decimal penny, a
>> denomination which has never existed.
>
> I see. Thanks for the clarification.

Also, 'single' is not a Java keyword.

--
Lew
 
 
Lew





PostPosted: 2008-6-3 8:02:00 Top

java-programmer >> Comparing two long numbers Lew wrote:
>> 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>

John B. Matthews wrote:
> 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;

I prefer the first and third of your examples.

--
Lew
 
 
Daniele Futtorovic





PostPosted: 2008-6-3 8:24:00 Top

java-programmer >> Comparing two long numbers On 2008-06-03 02:00 +0100, Lew allegedly wrote:
> Also, 'single' is not a Java keyword.

No shit. Was supposed to be a joke. Y'all no fun anymore.



--
DF.
to reply privately, change the top-level domain
in the FROM address from "invalid" to "net"
 
 
Lew





PostPosted: 2008-6-3 8:28:00 Top

java-programmer >> Comparing two long numbers Daniele Futtorovic wrote:
> On 2008-06-03 02:00 +0100, Lew allegedly wrote:
>> Also, 'single' is not a Java keyword.
>
> No shit. Was supposed to be a joke. Y'all no fun anymore.

Ah.

:-}

--
Lew
 
 
QXJuZSBWYWpow7hq





PostPosted: 2008-6-3 10:07:00 Top

java-programmer >> Comparing two long numbers Daniele Futtorovic wrote:
> On 2008-06-02 13:22 +0100, Lew allegedly wrote:
>> Lew wrote:
>>>> 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?
>>
>> John B. Matthews wrote:
>>> 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. :-)
>>
>> 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?

I am sure that I would use 1.0, but out of all the Java developers
there has to be some that prefer 1d.

Arne

 
 
QXJuZSBWYWpow7hq





PostPosted: 2008-6-3 10:08:00 Top

java-programmer >> Comparing two long numbers Daniel Pitts wrote:
> Arne Vajh酶j wrote:
>> Mark Space wrote:
>>> Arne Vajh酶j wrote:
>>>> 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.
>>
>> I am pretty sure that C also has default double and explicit f
>> for float.
>>
> I believe 1.5d is a compiler error in C.

Yet another variation.

Arne
 
 
John B. Matthews





PostPosted: 2008-6-3 14:24:00 Top

java-programmer >> Comparing two long numbers In article <email***@***.com>,
Lew <email***@***.com> wrote:

> Lew wrote:
> >> 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>
>
> John B. Matthews wrote:
> > 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;
>
> I prefer the first and third of your examples.

Wait, I forgot ...ASPECT_RATIO = Rational.doubleValue(7, 10); :-)

John
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
 
 
Andreas Leitgeb





PostPosted: 2008-6-3 14:48:00 Top

java-programmer >> Comparing two long numbers John B. Matthews <email***@***.com> wrote:
>> > 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;
> Wait, I forgot ...ASPECT_RATIO = Rational.doubleValue(7, 10); :-)

Why final, anyway? As if the eye were never to move... :-)

 
 
John B. Matthews





PostPosted: 2008-6-3 18:30:00 Top

java-programmer >> Comparing two long numbers In article <email***@***.com>,
Andreas Leitgeb <email***@***.com> wrote:

> John B. Matthews <email***@***.com> wrote:
> >> > 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;
> > Wait, I forgot ...ASPECT_RATIO = Rational.doubleValue(7, 10); :-)
>
> Why final, anyway? As if the eye were never to move... :-)

It was an internal proportion for rendering a component that filled its
container. The container was responsible for assuming a pleasing aspect.

John
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
 
 
Andreas Leitgeb





PostPosted: 2008-6-3 20:59:00 Top

java-programmer >> Comparing two long numbers John B. Matthews <email***@***.com> wrote:
> It was an internal proportion for rendering a component that filled its
> container. The container was responsible for assuming a pleasing aspect.

Perhaps, 0.61803398875 would have been even more pleasing than 0.7 :-)

 
 
John B. Matthews





PostPosted: 2008-6-3 23:16:00 Top

java-programmer >> Comparing two long numbers In article <email***@***.com>,
Andreas Leitgeb <email***@***.com> wrote:

> John B. Matthews <email***@***.com> wrote:
> > It was an internal proportion for rendering a component that filled its
> > container. The container was responsible for assuming a pleasing aspect.
>
> Perhaps, 0.61803398875 would have been even more pleasing than 0.7 :-)

Yes, but surely you mean 2 / (1 + Math.sqrt(5d))! Clearly there is an
immanent need for Math.PHI :-)

John
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
 
 
Andreas Leitgeb





PostPosted: 2008-6-4 1:09:00 Top

java-programmer >> Comparing two long numbers John B. Matthews <email***@***.com> wrote:
>> Perhaps, 0.61803398875 would have been even more pleasing than 0.7 :-)
> Yes, but surely you mean 2 / (1 + Math.sqrt(5d))! Clearly there is an
> immanent need for Math.PHI :-)

I meant (Math.sqrt(5.)-1)/2, which is theoretically the same, but
numerically more stable, since the divisor is simpler.
But then it would be Math.PHI, and at least as exact as each of the
formulae, if not better than both. :-)

 
 
John B. Matthews





PostPosted: 2008-6-4 2:06:00 Top

java-programmer >> Comparing two long numbers In article <email***@***.com>,
Andreas Leitgeb <email***@***.com> wrote:

> John B. Matthews <email***@***.com> wrote:
> >> Perhaps, 0.61803398875 would have been even more pleasing than 0.7 :-)
> > Yes, but surely you mean 2 / (1 + Math.sqrt(5d))! Clearly there is an
> > immanent need for Math.PHI :-)
>
> I meant (Math.sqrt(5.)-1)/2, which is theoretically the same, but
> numerically more stable, since the divisor is simpler.
> But then it would be Math.PHI, and at least as exact as each of the
> formulae, if not better than both. :-)

You're right: I inverted but didn't simplify! But isn't
(Math.sqrt(5.)-1)/2 equal to 1 / phi?

John
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews