floating point problem

T

Tak-Shing Chan

If it were nothing but C, then the group could be replaced by a pointer to
the ANSI/ISO C standard.

The things that really get posted here are usually mixtures of C and C
related things and things unrelated to C. The amount of tangentiality that
is allowed is probably a bit less than other groups, but that keeps the
group focused.

I recently went off on a tangent about algorithms. Now, we write algorithms
in C (and we might also say that we use C to write algorithms). We can
stray further and further from the core ideas until we are talking about
rainbows and aluminum (which is munimula, when spelled backwards).
Eventually, we must arrive at something which no longer holds any interest
for the vast majority of denizens of c.l.c.

But of course, this post is topical (along with both Richard's post and your
response) because it is a discussion of topicality, which is always
topical -- at least according to long established USENET tradition.

``Primary'' and ``tangentiality'' are antonyms. As far as I
know, computer science is not the primary purpose of this group.

Tak-Shing
 
D

Dann Corbit

Tak-Shing Chan said:
``Primary'' and ``tangentiality'' are antonyms. As far as I
know, computer science is not the primary purpose of this group.

No, but a subset of computer science is the primary purpose of the group.
 
J

Joe Wright

hi....i have encountered strange problem regarding floating point
comparison...the problem is...

main()
{
float a=0.7;
if(0.7 > a)
printf("hi");
else
printf("hello");
}

i think the answer should have hello...but strangely it is hi....but
for a=0.8 the answer is hello...again for a=0.9 the answer is hi....the
program is run on a linux system....if anybody explains this problem it
will be very helpful...thanx in advance...bye..

regards,

eric
float a = 0.7 has a precision of 24 bits. 0.7 is a double with precision
(here) of 53 bits. As it turns out the double 0.7 is larger than the
float 0.7 by a bit. :)

The float converted to double:
6.9999998807907104e-01

The double:
6.9999999999999996e-01
 
M

Mark McIntyre

One might suspect most programmers are aware it's impossible to
represent an infinite number of distinct states in a computer.

One might, but one would be disappointed. An alarmingly large number
of computer programmers seem to think that computers are exact.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
R

Richard Heathfield

Tak-Shing Chan said:
In the above quote, Richard said ``C and computer science''
instead of just ``C''---and then he ended with ``other reasons...
not the primary purpose of the group''. This seems to suggest
that computer science is one of the primary purposes here!

Bear in mind that my view is not normative! I am merely stating my opinion,
which is that C discussions are the primary purpose of the group.

Computer science discussions are not strictly topical, but are a
nice-to-have when they flow naturally from a topical discussion.
 
T

Tak-Shing Chan

No, but a subset of computer science is the primary purpose of the group.

The original context is ``C and computer science''. It is
quite clear to me that this is not referring to a subset. More
to the point, if the subset in question is ``general issues of
the C programming language, as defined by the ANSI/ISO language
standard'' (Billy Chambless), then the phrase ``C and computer
science'' becomes redundant.

Tak-Shing
 
T

Tak-Shing Chan

Computer science discussions are not strictly topical, but are a
nice-to-have when they flow naturally from a topical discussion.

In other words original posters aren't allowed to post
off-topic while the question-answerers (regulars) can as long as
it's deemed ``natural''. Interesting view. :)

Tak-Shing
 
R

Richard Heathfield

Tak-Shing Chan said:
In other words original posters aren't allowed to post
off-topic

That depends on what you mean by "allowed". OPs /do/ post off-topic
material, after all.
while the question-answerers (regulars) can as long as
it's deemed ``natural''.

Nobody is doing any deeming, and anybody /can/ post what they like - it is
not a question of whether they /can/, but whether they /should/.

Kaz once talked about solid, topical articles being like pennies in the
bank, and off-topic articles being dollar withdrawals. That's a pretty good
analogy. And of course the trick is to stay in credit. (Warning: that's
just an analogy, and is not to be taken literally - nobody is doing the
accounting, as far as I am aware.)
 
T

Tak-Shing Chan

Kaz once talked about solid, topical articles being like pennies in the
bank, and off-topic articles being dollar withdrawals. That's a pretty good
analogy. And of course the trick is to stay in credit. (Warning: that's
just an analogy, and is not to be taken literally - nobody is doing the
accounting, as far as I am aware.)

I do not think that this is a good analogy. IMHO the level
of expertise and/or effort required to answer the question should
be taken into account. I have in mind the mini-essays from Chris
Torek which in the real world should worth 20 times more than the
average on-topic posts (in terms of the post-to-pennies ratio).

Tak-Shing
 
D

Dann Corbit

Tak-Shing Chan said:
I do not think that this is a good analogy. IMHO the level
of expertise and/or effort required to answer the question should
be taken into account. I have in mind the mini-essays from Chris
Torek which in the real world should worth 20 times more than the
average on-topic posts (in terms of the post-to-pennies ratio).

Which is to say that some deposits are a dollar or ten dollars or more.

So there are individual posters (Tanmoy Bhattacharya, Dan Pop, Chris Torek,
Peter Seebach, etc.) who have a huge balance on hand (c.l.c billionaires?).

Other posters are way, way, way overdrawn and have never managed a positive
balance.

Different posters see this forum in different ways. But I think a sensible
goal is to add value to the forum, which fits our analogy nicely. After
reading any chain of messages, I should walk away with some incremental
improvement in my understanding.

(Or at least a refresher of what I already knew).

So we should strive to have threads that impart focused knowledge to the
readers that is clear, unambiguous, and enlightening [not to mention
correct].

IMO-YMMV.
 
R

Richard Heathfield

Tak-Shing Chan said:
I do not think that this is a good analogy.

That is your prerogative. Feel free to take it up with Kaz next time he
shows up in here.
IMHO the level
of expertise and/or effort required to answer the question should
be taken into account.

Quite so - all solid, topical articles earn pennies[1], but some earn more
pennies than others. In other words, the analogy holds (thus far).
I have in mind the mini-essays from Chris
Torek which in the real world should worth 20 times more than the
average on-topic posts (in terms of the post-to-pennies ratio).

At the very least.


[1] What do you mean, you haven't been getting your cheques? Take it up with
your ISP.
 
R

Ronald Bruck

Mark McIntyre said:
One might, but one would be disappointed. An alarmingly large number
of computer programmers seem to think that computers are exact.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

Or as Scotty put it on Star Trek, "The more complicated you make the
plumbing, the easier it is to stop it up." (Or something like that.)

Kernighan's is the, er, more polite of the two... And I wanted Mark to
know SOMEBODY, at least, appreciates his digging it out.

Sorry for the off-topicality...
 
D

Dik T. Winter

> Richard Heathfield wrote:
>
>
> One might suspect most programmers are aware it's impossible to
> represent an infinite number of distinct states in a computer.

Ah, but Richard is incorrect here. 2^32 bit patterns can represent *at
most* 2^32 different values. There can be different representations that
represent the same value.
 
R

Richard Heathfield

Dik T. Winter said:
Ah, but Richard is incorrect here.

I beg to differ...
2^32 bit patterns can represent *at
most* 2^32 different values. There can be different representations that
represent the same value.

....but I'll settle for "insufficiently precise". :)
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top