pow(2, 1/2) != pow(2, 0.5) problem

O

Old Wolf

Walter said:
If you are going to talk about "classical" interpretations
and "familiar symbols", then Oberon does *not* "get it right".
The "classical" meaning of / (solidus), dating back hundreds of
years, is as a seperator between shilling and pence in writing currency.
The use of solidus as meaning division only goes back a little over
a hundred years according to OED. The use of the solidus as
integer division in C (1972) is directly taken from the same use
in Kerninghan's B (1970) -- predating the decimalization of
UK coinage in 1971.

On pen and paper (or stylus and tablet), you would write a fraction
as:
1
-
2
or
1
/
2

I'd always assumed that "1 / 2" was the natural result of converting
the latter writing style into a form suitable for typing on a computer,
and as such, you could say that using '/' for division goes back
hundreds of years.

Of course, I wouldn't presume to disagree with OED :)
 
R

Richard Bos

akarl said:
No. Tell someone on the street that 1/2 equals 0.

Tell someone on the street that % means "modulus".

Tell someone on the street that ! means "not".

Tell someone on the street that "switch" means "make a choice".

Tell someone on the street that "#" means "a preprocessor directive will
follow", and they're likely to say "a pre-WHAT? Di-WHAT?", and in the
rare case that they're both USAnian and intelligent enough to know the
word "directive", they might well say "Directive? Say, you're not one of
them unamerican pink-livered commie traitors, are you?"

What someone on the street understands is completely irrelevant to the
design of programming languages.
No, at least not according to the terminology used in "Abstract Algebra"

So? According to the terminology used in biology, division is something
cells do. That is about as relevant.

Richard
 
W

Walter Roberson

In the March 1995 edition of "The Programming Language Oberon-2",
section 8.2.2, `/' is called "real quotient".

Irrelevant. The language referenced was Oberon, not Oberon-2 .
You wouldn't say that C had a particular property when it was
really C++ you were talking about.
 
W

Walter Roberson

On pen and paper (or stylus and tablet), you would write a fraction
as:
1
-
2

That form appears to be fairly old, probably al-Hassar around 1200.

That form was introduced around 1718 in small circulation, and
does not appear to have been made common until around 1845 by De Morgan.

http://members.aol.com/jeff570/fractions.html

I'd always assumed that "1 / 2" was the natural result of converting
the latter writing style into a form suitable for typing on a computer,

Apparently the horizontal fraction bar ('vinculum') was hard to
print mechanically.
 
A

akarl

Richard said:
Tell someone on the street that % means "modulus".

`%' is an infix operator, so at least it can't mean "percentage".
Tell someone on the street that ! means "not".

! is a prefix operator, so it can't be the exclamation mark as used in
ordinary language, e.g. "Stop!".

....and so on...

My point is that `/' is not the ordinary mathematical division operator
when the operators are integers. That's why the original poster was
confused.
What someone on the street understands is completely irrelevant to the
design of programming languages.

Okay, then why not choose the symbols completely at random: `*' for
addition, `+' for division...
So? According to the terminology used in biology, division is something
cells do. That is about as relevant.

We are not talking about the interpretation of the word "division", but
the symbol `/'. If you say that the interpretation of `/' as a
mathematical symbol is irrelevant I'm afraid I can't take you seriously.
 
A

akarl

Walter said:
Irrelevant. The language referenced was Oberon, not Oberon-2 .
You wouldn't say that C had a particular property when it was
really C++ you were talking about.

It doesn't matter. `/' is the same operator in both Oberon and Oberon-2.
Niklaus Wirdt knows exactly what he is doing.
 
J

Jean-Claude Arbaut

Le 16/06/2005 13:56, dans [email protected], « akarl »
Richard said:
Tell someone on the street that % means "modulus".

`%' is an infix operator, so at least it can't mean "percentage".
Tell someone on the street that ! means "not".

! is a prefix operator, so it can't be the exclamation mark as used in
ordinary language, e.g. "Stop!".

...and so on...


My point is that `/' is not the ordinary mathematical division operator
when the operators are integers. That's why the original poster was
confused.
[...]
Okay, then why not choose the symbols completely at random: `*' for
addition, `+' for division...
[...]

We are not talking about the interpretation of the word "division", but
the symbol `/'. If you say that the interpretation of `/' as a
mathematical symbol is irrelevant I'm afraid I can't take you seriously.

It's stupid, the C '/' is always a division, even if it's a one you
don't like. Divide integers and you get an integer, divide doubles
and you get a double. What did you expect, dude ?

And yes, 1/2 equals 0. You know what a quotient is, don't you ?
Even kids know that.
 
A

akarl

Jean-Claude Arbaut said:
Le 16/06/2005 13:56, dans [email protected], « akarl »
Richard said:
No. Tell someone on the street that 1/2 equals 0.

Tell someone on the street that % means "modulus".

`%' is an infix operator, so at least it can't mean "percentage".

Tell someone on the street that ! means "not".

! is a prefix operator, so it can't be the exclamation mark as used in
ordinary language, e.g. "Stop!".

...and so on...


My point is that `/' is not the ordinary mathematical division operator
when the operators are integers. That's why the original poster was
confused.

[...]

Okay, then why not choose the symbols completely at random: `*' for
addition, `+' for division...

[...]

We are not talking about the interpretation of the word "division", but
the symbol `/'. If you say that the interpretation of `/' as a
mathematical symbol is irrelevant I'm afraid I can't take you seriously.


It's stupid, the C '/' is always a division, even if it's a one you
don't like.

....a one you don't like? Can you clarify that.
Divide integers and you get an integer, divide doubles
and you get a double. What did you expect, dude ?

I expect to get a floating point number. Since the result of dividing
two integers is sometimes an integer (when the remainder is zero) and
sometimes a rational number (when the remainder is non-zero) the only
sensible type of the result of the operation is therefor a floating
point number.
And yes, 1/2 equals 0. You know what a quotient is, don't you ?
Even kids know that.

If you are being ironic, you are very funny. You mix up division of
integers as defined by C and "real" mathematical division:

1 = 0*2 + 1

so the quotient of 1/2 is 0 and the remainder is 1.
 
J

Jean-Claude Arbaut

Le 16/06/2005 14:28, dans [email protected], « akarl »
...a one you don't like? Can you clarify that.

You seem to dislike C's notation for division, that's all I say.
In fact, I've never seen "2 DIV 3" in textbooks, but maybe you have ?
I wouldn't even be surprised to see '%' for remainder in textbooks,
as there is no standard notation for that. I saw "2 mod 3", but it's
mereley a new use of an old notation that hasn't the same meaning:

a = b (mod n) said:
I expect to get a floating point number. Since the result of dividing
two integers is sometimes an integer (when the remainder is zero) and
sometimes a rational number (when the remainder is non-zero) the only
sensible type of the result of the operation is therefor a floating
point number.

And sometimes you want the quotient. C is able to compute both
quotient and FP approximation, you just have to cast operands.
If you are being ironic, you are very funny. You mix up division of
integers as defined by C and "real" mathematical division:

1 = 0*2 + 1

so the quotient of 1/2 is 0 and the remainder is 1.

And the difference is ?
 
D

davebsr

[...snip disagreement about syntax ..]

I hate to interrupt here, but aren't you two arguing about two seperate
things? Isn't akarl talking about how programming languages _should_
be, and others talking about how C _is_?

Either akarl wants to change the way C does things, which is foolish,
or he is saying that there should be a better way - a more usable
programming language. Would anyone here argue that C is the peak of
programming language usability, never to be surpassed? And just as
clearly, isn't it foolish to try and argue that the way C does
something should be changed immediately because it doesn't make sense
to a non-programmer?
 
J

Jean-Claude Arbaut

Le 16/06/2005 15:40, dans
(e-mail address removed), « davebsr »
[...snip disagreement about syntax ..]

I hate to interrupt here, but aren't you two arguing about two seperate
things? Isn't akarl talking about how programming languages _should_
be, and others talking about how C _is_?

Either akarl wants to change the way C does things, which is foolish,
or he is saying that there should be a better way - a more usable
programming language. Would anyone here argue that C is the peak of
programming language usability, never to be surpassed? And just as
clearly, isn't it foolish to try and argue that the way C does
something should be changed immediately because it doesn't make sense
to a non-programmer?

You are completely right
 
A

akarl

Jean-Claude Arbaut said:
You seem to dislike C's notation for division, that's all I say.

Yes, I dislike C's notation for calculating the quotient (excluding the
remainder) of integer division as it means something different in
mathematics.
In fact, I've never seen "2 DIV 3" in textbooks, but maybe you have ?
I wouldn't even be surprised to see '%' for remainder in textbooks,
as there is no standard notation for that. I saw "2 mod 3", but it's
mereley a new use of an old notation that hasn't the same meaning:

a = b (mod n) <=> a-b = k*n

In mathematics we would use the floor brackets around 2/3 to get `2 DIV
3'. As you say, there doesn't seem to be any standard operator for the
remainder of integer division.
And sometimes you want the quotient. C is able to compute both
quotient and FP approximation, you just have to cast operands.

Of course I can get both, but that's not the issue here.
And the difference is ?

In C, 1/2 equals 0. In mathematics, 1/2 is not equal to 0.
 
R

Richard Bos

akarl said:
Yes, I dislike C's notation for calculating the quotient (excluding the
remainder) of integer division as it means something different in
mathematics.

C is not mathematics. C is programming. Get over it.
In C, 1/2 equals 0. In mathematics, 1/2 is not equal to 0.

Exactly. And in layout, 1/2 is one column of text running over the width
of two ordinary columns. And in commerce, 1/2 is a libra and two unciae.
Again: get over it.

Richard
 
A

akarl

davebsr said:
[...snip disagreement about syntax ..]


I hate to interrupt here, but aren't you two arguing about two seperate
things? Isn't akarl talking about how programming languages _should_
be, and others talking about how C _is_?

Either akarl wants to change the way C does things,

No, of course not.
which is foolish, or he is saying that there should be a better way - a
> more usable programming language.
Yes.

Would anyone here argue that C is the peak of
programming language usability, never to be surpassed? And just as
clearly, isn't it foolish to try and argue that the way C does
something should be changed immediately because it doesn't make sense
to a non-programmer?

You probably mean "doesn't make sense to non-Fortran/C/C++/Java...
programmers". I think it's important to understand both the good and the
bad design choices of a programming language.
 
I

icub3d

One thing to remember though, many high schools consider a computer
science class to meet a language requirement. I didn't have to take a
language (German, French, etc.) because I took Computer Science I and
II.

To this day, it's still difficult to get a computer to express or
represent exactly what we mean. Similarly, the C language doesn't
always perform as *everyone* expects it would. Thus the standard was
created. It helps us interpret what int i = 1/2; will do in the C
language, when "what does 1 divided by 2 equal?" will not product the
same result in the English Language.
 
J

Jean-Claude Arbaut

Le 16/06/2005 15:48, dans [email protected], « akarl »
In mathematics we would use the floor brackets around 2/3 to get `2 DIV
3'. As you say, there doesn't seem to be any standard operator for the
remainder of integer division.

I find this notation awful: why use an intermediate larger set ? The integer
division has nothing to do with rationnal numbers. It's the solution to
an optimization problem: for a,b > 0 find argmin(b-x*a). A rationnal is
a proportion, intuitively the current notation is absurd. Yet I won't
try to convince mathematicians to change their habits.

/ n \ p
And what about | |, denoted C in french ?
\ p / n
 
C

Chris Croughton

The use of solidus as meaning division only goes back a little over
a hundred years according to OED. The use of the solidus as
integer division in C (1972) is directly taken from the same use
in Kerninghan's B (1970) -- predating the decimalization of
UK coinage in 1971. Thus if you want to argue that C should have
adopted "classical" usages, then the use of the solidus should
indicate values in which the first portion is weighted 20 times the
second portion.

12 times, not 20 (3/9d meant 3 shillings and 9 pence, 12 pence to a
shilling, 20 shillings to the pound). I grew up with real (pre-decimal)
currency...

It is also commonly used for dates in the UK and the USA -- 16/6/2005 in
the UK, 6/16/2005 in the USA for todays date (2005-06-16 in ISO 8601).
Which, of course, is just as irrelevant to how it is used in C...

Chris C
 
W

Walter Roberson

Okay, then why not choose the symbols completely at random: `*' for
addition, `+' for division...

FORTRAN I used the letter X for multiplication.

AXB meant A multiplied by B.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top