Comparing two numbers

P

pete

Chris said:
You might accept that as a grammatical constraint; I don't.

As side-curiosity, would you accept, using "your" definition

"find the greatest of a, b, and c"
where a = 42, b = 17, c = 42
?

I would.
I learned English the same way as purifer did.
 
M

Michael Wojcik

If a and b are unsigned int, and either one is UINT_MAX, you have
division by zero.

If a and b are int, and either one is INT_MAX, you have overflow.

Yes, in one draft of that post I had a qualification about remaining
below the maximum value of the type of a and b, but apparently I
removed it during editing. It's so obvious I hardly think it's worth
pointing out anyway; we could make the same criticism of most code
snippets posted to c.l.c. Clearly the expression above fails to work
for values *greater* than the maximum of the type, since we can't
even put them into a and b; should I have mentioned that?
 
M

Michael Wojcik

You might accept that as a grammatical constraint; I don't.

It's a question of usage, not grammar. No matter of grammar is under
debate. English grammar tells us that "greatest" is the superlative
form of the adjective "great", and that "greater" is the comparative
form. Whether the superlative is properly used for a set of fewer
than three items is a matter of usage.

Preferring the comparative when only two items are being compared is
certainly longstanding and widespread among those who advocate
specific usages in English.

--
Michael Wojcik (e-mail address removed)

Thus, the black lie, issuing from his base throat, becomes a boomerang to
his hand, and he is hoist by his own petard, and finds himself a marked man.
-- attributed to a "small-town newspaper editor in Wisconsin"
 
J

jmachine

There are tons of asshole on programmng forum so beware.
They forget what it was like to be new I guess.

l00pyl
 
R

Richard Bos

Preferring the comparative when only two items are being compared is
certainly longstanding and widespread among those who advocate
specific usages in English.

Preferring it, yes. Demanding it of others, no. "The greater of the two"
is correct. "The greatest of the two" is not wrong.

Richard
 
C

CBFalconer

Richard said:
Preferring it, yes. Demanding it of others, no. "The greater of the
two" is correct. "The greatest of the two" is not wrong.

Go ahead. You have my permission (if not blessing) to cavalierly
use 'greatest' as you wish. Do not misconstrue this as a license
to use the broken google usenet interface, nor to top-post, nor to
fail to snip, nor to 'edit' quoted material, nor to use
'doodspeak', nor to attach binaries. :) I am sure you have been
eagerly awaiting this permission.
 
M

Michael Wojcik

Well, I'm not convinced, but that's partly because my notion of
grammar for natural language is as a description of usage,

Exactly. English grammar is descriptive (specifically, of syntax),
not proscriptive.
so I'm not making the distinction in the same way you are.

Clearly, but that doesn't follow from grammar being a description
of usage. If grammar describes usage, then an error of grammar
can only be an error of description, not an "error" in the actual
use of language in the statement in question.
I think my position here is that I'd use "greatest" and "greater" without
organised preference, for any non-empty collections of items,

I wouldn't try to stop you. (I actually do possess a secret doomsday
weapon with which I could enforce my language preferences on everyone,
but I don't wield it for trifles.) I prefer the comparative when
dealing with two items, but the use of the superlative in that context
is pretty widespread. The comparative for more than two ("he was the
wittier of the three"?) is, I think, less common, but understanding
probably won't be dramatically impaired by it.
but of course I might be empirically wrong

In a matter of usage? I'm not sure empiricism applies.
and in any case my usage has been heavily influenced by mathematics.

Where I agree that distinguishing the dual case would be a pointless
inconvenience.
*I* am happy to say "all my helicopters are heavily armed" and "our
biggest cat is on the bed". (But I might not be so happy to say that
to a policeman.)

Those cat police are a caution, aren't they?

--
Michael Wojcik (e-mail address removed)

They had forgathered enough of course in all the various times; they had
again and again, since that first night at the theatre, been face to face
over their question; but they had never been so alone together as they were
actually alone - their talk hadn't yet been so supremely for themselves.
-- Henry James
 
A

Albert van der Horst

It's a real sad thing to know, Sir... I didn't expect that my post would
make you think that it was my homework... I'm an Electronics Engineer, but
i'm interested a lot in programming... One of my friends asked me this
question in a mail. I just pasted that mail here... For your information i
even said "Can you please help me solve the problem" Why would I say huh
and all kinds of stuff and then ask people to solve the problem? I could
have directly given the problem...
Anyway, Sorry if i mislead you guys... Thank you for the replies.. Atleast
if possible, please give me some ideas...

The following is not correct. But there is an idea inside.
Though it is not correct, it works.

x = -(a<b);
y = -!x;
max = (b&x)|(y&a);

(You may want to take a course DEC Alpha assembler programming.)
 
M

Mike Wahler

Richard Bos said:
Preferring it, yes. Demanding it of others, no. "The greater of the two"
is correct. "The greatest of the two" is not wrong.

The greatest of 2 is 2.

Now someone please write a C expression which
proves this. :)

-Mike
 
B

Ben Pfaff

Preferring it, yes. Demanding it of others, no. "The greater of the two"
is correct. "The greatest of the two" is not wrong.

I think the former example is the best usage.
 
A

Albert van der Horst

Keith Thompson said:
Incidentally, I can think of a reasonable reason to want to find the
greater of two numbers without using certain constructs. Conditional
branches, on some systems, can cause performance problems by messing
with pipelining, instruction caches, and other off-topic stuff. If
performance is sufficiently important, it just might be worthwhile to
micro-optimize such an operation. If you can state the restrictions
in portable C terms (even if the motivation for the restrictions is
off-topic), you might have an interesting question.

Like this?
------------
int test(int a, int b)
{
return a<b? b: a;
}
int test2(int a, int b)
{
int c;

if (a<b)
c=b;
else
c=a;

return c;
}
-----------------------
This is what the gnu c-compiler delivers on DEC alpha
(-O3). There is no jump in sight. The code is the same
for both functions.

For the uninitiated: I have commented the code. .file 1 "aap.c"
.version "01.01"
.set noat
gcc2_compiled.:
__gnu_compiled_c:
..text
.align 3
.globl test
.ent test
test:
$test..ng:
.frame $30,0,$26,0
.prologue 0
cmple $17,$16,$1 r1 = (a<=b);
bis $16,$16,$0 r0 = b; (literally r0 = b|b; )
cmoveq $1,$17,$0 if (r1) r0 = a;
ret $31,($26),1
.end test
.align 3
.globl test2
.ent test2
test2:
$test2..ng:
.frame $30,0,$26,0
.prologue 0
cmple $16,$17,$1
bis $17,$17,$0
cmoveq $1,$16,$0
ret $31,($26),1
.end test2
.ident "GCC: (GNU) egcs-2.90.27 980315 (egcs-1.0.2 release)"
-------------

Or is this what you mean by off topic?



--
 
M

Mike Wahler

Albert van der Horst said:
The following is not correct. But there is an idea inside.
Though it is not correct, it works.

x = -(a<b);
y = -!x;
max = (b&x)|(y&a);

(You may want to take a course DEC Alpha assembler programming.)

Since I think enough time has passed :), and I haven't
seen the 'array method' posted yet, here it is (if the
inputs are equal, returns the first.):

int greater(int n1, int n2)
{
int a[2] = {n1, n2};
return a[n1 < n2];
}

-Mike
 
K

Keith Thompson

Albert van der Horst said:
Like this?
[snip example showing generated code with no jumps]

Good point; most compilers do a pretty good job of optimizing jumps
away if it makes sense to do so for a given processor (and, just as
important, not doing so if it doesn't make sense).

I'll amend my above statement to say that this kind of
micro-optimization might make sense given the above circumstances *if*
you don't have a compiler that can do the optimization for you. (That
may not be an issue these days.)
 
C

Chris Dollin

Michael said:
I wouldn't try to stop you. (I actually do possess a secret doomsday
weapon with which I could enforce my language preferences on everyone,
but I don't wield it for trifles.) I prefer the comparative when
dealing with two items, but the use of the superlative in that context
is pretty widespread. The comparative for more than two ("he was the
wittier of the three"?) is, I think, less common, but understanding
probably won't be dramatically impaired by it.


In a matter of usage? I'm not sure empiricism applies.

Sorry, I mean that I might be empirically wrong about my usage patterns.
(Self-observation is tricky, even more subject to selection effects than
observation of others.)
Those cat police are a caution, aren't they?

There appearance can be arresting, also.
 
M

Mabden

purifier said:
Enough of those insults... I'm sorry for bothering you guys... I guess this
forum is filled with all time intellectuals... I already explained that I'm
an Electronics Engineer just beginning to learn C... Now why would I lie
about my profession? Come on...there is no reason to... Ok...if it was one
post insulting me then it's ok but it seems that everyone who posts a reply
just insults in some or the other way... It is a pity that you guys are so
rude to beginners like me... Now, how do you want me to prove that i'm not
asking you to do my homework...? Do you want me to sign a bond or what?
The only reason i came here was thinking that this is an open forum... and
thought i could ask for some help... Now, how do i show you my work if I
didn't even understand the problem... Anyway, I won't bother you guys
again... You can talk all the hi fi stuff...

And Admin Sir, Let me finally congratulate you in having such a wonderful
forum... All the above things were my personal opinions because i was hurt
a lot after posting here but your board is definitely helpful for many
experienced programmers to interact... Keep it up Sir...

purifier

douche-bag!
 
M

Mabden

CBFalconer said:
Since all potential homework problems are immeditately rejected or
argued over for a week or so, the mechanism ensures that any
homework answers arrive too late for submission, and thus do not
exacerbate the flood of incompetent programmers.

Except those who research the archives!

....which has never happened, or they would have found last year's crop
of "Solve cold fishions without using fish or ions" problems'
"solutions".

Ah, reasearch. What ever happened to Rea, anyway?
 
M

Mabden

Chris Dollin said:
That's a pretty useless definition, then. Me, I can find the greatest
of *one* thing. It's the greatest of *no* things that's tricky.

What is the greatest thing about pissing on your shoes?

The only thing I can think of is me doing it...
 
D

Dave Thompson

Kenneth Brody wrote:

That's a pretty useless definition, then. Me, I can find the greatest
of *one* thing. It's the greatest of *no* things that's tricky.

This is the difference between people and mathematicians. :)

In Fortran MAXVAL of an empty (sub)array produces the identity, -huge,
and MINVAL respectively +huge. ISTR APL did essentially the same, but
that memory is faint and I have no reference at hand to check.

Now, the greatest (or whatever) of a *negative number* of things ...

And in those situations where one person says to another "I have a
little nothing for you" it definitely isn't no thing and usually is a
thing nowhere near least by the relevant metric(s). <G>

- David.Thompson1 at worldnet.att.net
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top