Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > pow(2, 1/2) != pow(2, 0.5) problem

Reply
Thread Tools

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

 
 
Old Wolf
Guest
Posts: n/a
 
      06-15-2005
Walter Roberson wrote:
>
> 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

 
Reply With Quote
 
 
 
 
Michel Rouzic
Guest
Posts: n/a
 
      06-16-2005

> C is correct.


I dont doubt it

 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      06-16-2005
akarl <(E-Mail Removed)> wrote:

> Lawrence Kirby wrote:
> > When used as an operator in C / always denotes division.

>
> 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.

> > And for many people that is the expected result.

>
> 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
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      06-16-2005
In article <W12se.140387$(E-Mail Removed)>,
akarl <(E-Mail Removed)> wrote:
>Walter Roberson wrote:
>> The Oberon Report indicates that / is "quotient" and DIV is
>> "integer quotient".


>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.
--
'The short version of what Walter said is "You have asked a question
which has no useful answer, please reconsider the nature of the
problem you wish to solve".' -- Tony Mantler
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      06-16-2005
In article <(E-Mail Removed). com>,
Old Wolf <(E-Mail Removed)> wrote:
>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.

>or
> 1
> /
> 2


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.
--
'The short version of what Walter said is "You have asked a question
which has no useful answer, please reconsider the nature of the
problem you wish to solve".' -- Tony Mantler
 
Reply With Quote
 
akarl
Guest
Posts: n/a
 
      06-16-2005
Richard Bos wrote:
>>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.

> 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...

>>>And for many people that is the expected result.

>>
>>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.


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.
 
Reply With Quote
 
akarl
Guest
Posts: n/a
 
      06-16-2005
Walter Roberson wrote:
> In article <W12se.140387$(E-Mail Removed)>,
> akarl <(E-Mail Removed)> wrote:
>
>>Walter Roberson wrote:
>>
>>>The Oberon Report indicates that / is "quotient" and DIV is
>>>"integer quotient".

>
>
>>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.


It doesn't matter. `/' is the same operator in both Oberon and Oberon-2.
Niklaus Wirdt knows exactly what he is doing.
 
Reply With Quote
 
Jean-Claude Arbaut
Guest
Posts: n/a
 
      06-16-2005



Le 16/06/2005 13:56, dans vNdse.140417$(E-Mail Removed), «*akarl*»
<(E-Mail Removed)> a écrit*:

> Richard Bos wrote:
>>> 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. 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.

 
Reply With Quote
 
akarl
Guest
Posts: n/a
 
      06-16-2005
Jean-Claude Arbaut wrote:
>
>
> Le 16/06/2005 13:56, dans vNdse.140417$(E-Mail Removed), « akarl »
> <(E-Mail Removed)> a écrit :
>
>
>>Richard Bos wrote:
>>
>>>>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.
 
Reply With Quote
 
Jean-Claude Arbaut
Guest
Posts: n/a
 
      06-16-2005

Le 16/06/2005 14:28, dans Dfese.140419$(E-Mail Removed), «*akarl*»
<(E-Mail Removed)> a écrit*:

> Jean-Claude Arbaut wrote:
>>


>>
>> 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.


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) <=> a-b = k*n

>> 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 sometimes you want the quotient. C is able to compute both
quotient and FP approximation, you just have to cast operands.

>> 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.


And the difference is ?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments