What does this mean??

T

Thomas G. Marshall

Roedy Green coughed up:
Turns out not:

Actually, I know that code (the one you quote below) already, before I
posted. When you said "any such library method", I was think also of C
(native code), but more so for languages that are far more platform specific
and as such tied to the vaguaries of their chipset.

/**
* Returns the absolute value of a <code>double</code> value.
* If the argument is not negative, the argument is returned.
* If the argument is negative, the negation of the argument is
returned.
* Special cases:
* <ul><li>If the argument is positive zero or negative zero, the
result
* is positive zero.
* <li>If the argument is infinite, the result is positive
infinity.
* <li>If the argument is NaN, the result is NaN.</ul>
* In other words, the result is the same as the value of the
expression:
....[rip]...

the interesting thing is the

0.0D -a
not just -a

Where's Patricia to explain the conditions those are not equivalent?

-a is a -1 * a. Perhaps this is to avoid the multiply. Perhaps for speed
issues, but perhaps also to maintain the NaN, +0, -0, as explained in the
comments?

For the record, the integer variants use unary -a.
 
J

Jack

And if every newbie in the java groups posted to .programmer instead of
.help, it would cost you very little to ignore them all.

Thomas, I'm not including myself in the advanced answerers group :)

So, I'm thinking that if I ever have an advanced question, I would
want advanced answerers to be here to reply. Still, I just came back
to this group recently to ask a question that I thought was more
advanced, but the answer was really simple - and was given by some
advanced people. So go figure :)
 
R

Rhino

My wife had a master's degree in Slavic Linguistics. Her graduate studies
were in Virginia. There were many students there with a Russian/southern-us
accent. Horrible.
I can just imagine... <CRINGE>

Kakaye po-Russki, y'all?

Rhino
 
T

Thomas G. Marshall

Roedy Green coughed up:
Who sent it ?

This should clear up most of your questions...

http://www.faqs.org/faqs/usenet/creating-newsgroups/part1/

A long time ago we had a vote about the various newsgroups and it has
remained unchanged since then.

No. This is an ongoing process. Please take a look at the following
authoritative documents.

Subject: How to Format and Submit a New Group Proposal
Newsgroups: news.announce.newgroups, news.groups

Subject: How to Write a Good Newsgroup Proposal
Newsgroups: news.announce.newgroups, news.groups

Subject: Usenet Newsgroup Creation Companion
Newsgroups: news.groups, news.announce.newusers, news.answers

Subject: What is Usenet?
Newsgroups: news.announce.newusers, news.admin.misc, news.answers

There was some formal process for taking such a vote, making the
proposals etc. It seemed a heck of a lot of fuss at the time, though
I was not involved in the details.

You do not understand. "There was" is not in the distant past. Read the
above link and posts.
 
T

Thomas G. Marshall

Thomas G. Marshall coughed up:
Roedy Green coughed up:
Turns out not:

Actually, I know that code (the one you quote below) already, before I
posted. When you said "any such library method", I was think also of C
(native code), but more so for languages that are far more platform
specific
and as such tied to the vaguaries of their chipset.

/**
* Returns the absolute value of a <code>double</code> value.
* If the argument is not negative, the argument is returned.
* If the argument is negative, the negation of the argument is
returned.
* Special cases:
* <ul><li>If the argument is positive zero or negative zero, the
result
* is positive zero.
* <li>If the argument is infinite, the result is positive
infinity.
* <li>If the argument is NaN, the result is NaN.</ul>
* In other words, the result is the same as the value of the
expression:
...[rip]...

the interesting thing is the

0.0D -a
not just -a

Where's Patricia to explain the conditions those are not equivalent?

-a is a -1 * a.

The second "a" is a casualty of war and is an article, not a variable. What
I should have written to be clear is:

"-b" is a "-1 * b"
 
T

Thomas G. Marshall

Roedy Green coughed up:

....[rip]...
The ternary syntax has the following advantages.

1. it suggest the logic is for some trivial adjustment, not something
profoundly relevant to the algorithm.

No. I'll leave it at that.

....[rip]...

4. You can tuck it in the middle of an expression.

YES! But there is an additional notion:

4b. It groups right to left for interesting looking expressions:

Take a look at this:

car = (a==1) ? FORD :
(a==2) ? CHEVY :
(a==3) ? HONDA :
DEFAULT;

{chucle}.


....[rip]...
 
H

hilz

: final int abs = i > 0 ? i : -i;
:
: I think this is nicer than the alternative:
: final int abs;
: if (i > 0) {
: abs = i;
: }
: else {
: abs = -i;
: }
:
: or even the more compect
: final int abs;
: if (i > 0) abs = i;
: else abs = -i;
:
The following would also work,

final int abs = i;
if (i < 0) abs = -i;



java.lang.Math.abs(...)
 
R

Roedy Green

You do not understand. "There was" is not in the distant past. Read the
above link and posts.

I am not saying there used to be a process for amending and now we are
bereft of a means to do so.

I am saying we have not changed things in quite a while. We did
however change them at one point using some formal procedure.
 
T

Thomas G. Marshall

zero coughed up:
What specific use do you see for a for loop, that couldn't be just as
easily
done with a while loop? Or, an even more obvious example, why would a
programming language need do...while? And to draw it into the absurd, why
do you need the * for multiplication? You could just as well do it with a
for - sorry, I meant while :p - loop using only addition. In fact, if
I'm
not mistaken that's what happens internally in the CPU anyway.

You are mistaken. Multiplication is not hardwired as successive additions,
and I have no idea why you would think that it would be.
 
R

Roedy Green

You are mistaken. Multiplication is not hardwired as successive additions,
and I have no idea why you would think that it would be.

Conceptually it is done with a series of shifts and adds, it is just
that it all happens in parallel, right?
 
R

Roedy Green

Conceptually it is done with a series of shifts and adds, it is just
that it all happens in parallel, right?

For an unsigned multiply a x b

You shift a every possible number of bits left 0 .. 31
If the corresponding bit in b is on, you include that shifted quantity
in the parallel adder.

The thing that takes the time is propagating carries
 
T

Thomas G. Marshall

Roedy Green coughed up:
Conceptually it is done with a series of shifts and adds, it is just
that it all happens in parallel, right?


This is not what zero suggested. Read again.
 
R

Roedy Green

This is not what zero suggested. Read again.

He said this happens "in the CPU" implying it was a hardware feature,
which is correct. Another plausible interpretation is that in byte
code, multiplies are handled with a shift and add loop. That is not
correct.
 
Z

zero

He said this happens "in the CPU" implying it was a hardware feature,
which is correct. Another plausible interpretation is that in byte
code, multiplies are handled with a shift and add loop. That is not
correct.

Yes I was talking about hardware. I don't know much about modern hardware
or CPUs, but I seem to remember a class in the distant past about computer
architecture, where it was said that multiplying was done by consecutive
additions.
 
T

Thomas G. Marshall

Roedy Green coughed up:
He said this happens "in the CPU" implying it was a hardware feature,
which is correct. Another plausible interpretation is that in byte
code, multiplies are handled with a shift and add loop. That is not
correct.

Neither is the whole of what he said Roedy! He said this:

Zero said:
And to draw it into the absurd, why do
you need the * for multiplication? You
could just as well do it with a for - sorry,
I meant while - loop using only addition.
In fact, if I'm not mistaken that's what
happens internally in the CPU anyway.

He said a loop using *only addition*.
 
T

Thomas G. Marshall

zero coughed up:
Yes I was talking about hardware. I don't know much about modern hardware
or CPUs, but I seem to remember a class in the distant past about computer
architecture, where it was said that multiplying was done by consecutive
additions.

You remember wrong.

When I went to school for computer science we had to take a substantial
amount of electrical engineering. The courseload for the class just beyond
our required classes had the engineers building a 32 bit multiplier out of
ttl hardware. The algorithm for n bits * n bits is of order n*n. O(n*n).

I've also implemented 32 and 64 bit multiplication algorithms on 8 bit
machines that had no such concept. You just don't do it by successive
additions, because you don't have to.

Can you imagine the multiplication of two large numbers? It could possibly
take a /very/ long time by cpu standards. They would never be able to
manage it in the handful of cycles that they do. 64 bits could handle 2
32bit numbers multiplied. That would be an iteration of 4 billion in
microcode or other chipset hardware!!!!!!

Read the section under "Long Multiplication".

http://www.answers.com/topic/multiplication-algorithm
 
Z

zero

You remember wrong.

When I went to school for computer science we had to take a
substantial amount of electrical engineering. The courseload for the
class just beyond our required classes had the engineers building a 32
bit multiplier out of ttl hardware. The algorithm for n bits * n bits
is of order n*n. O(n*n).

I've also implemented 32 and 64 bit multiplication algorithms on 8 bit
machines that had no such concept. You just don't do it by successive
additions, because you don't have to.

Can you imagine the multiplication of two large numbers? It could
possibly take a /very/ long time by cpu standards. They would never
be able to manage it in the handful of cycles that they do. 64 bits
could handle 2 32bit numbers multiplied. That would be an iteration
of 4 billion in microcode or other chipset hardware!!!!!!

Read the section under "Long Multiplication".

http://www.answers.com/topic/multiplication-algorithm

Ok I yield. You're right, I'm wrong.
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top