Bug/Gross InEfficiency in HeathField's fgetline program

  • Thread starter Antoninus Twink
  • Start date
J

Jean-Marc Bourguet

user923005 said:
I disagree. If there are any rational or exponential calculations,
then it is not possible.
Examples:
Depreciation calculations
Interest calculations
Investments (Future value, Present value, Annuities...)

My impression was that there are reglementary texts who precise exactly how
those should be computed, included the rounding rules.

BTW, I doubt very much that they have any relationship with the rounding
rules of any implementation of floating point, even decimal FP. And we
know the problems caused by double rounding.

Yours,
 
R

Richard Heathfield

Flash Gordon said:
Richard Heathfield wrote, On 05/11/07 23:40:


Not only can, but is actually required to be done exactly.

THANK you! At last someone sees what I'm getting at. I was beginning to
despair of my ability to explain this.
 
R

Richard Tobin

William Hughes said:
How many legs does a horse have if you call a tail
a leg? Four, calling a tail a leg does not make a tail
a leg.

It makes "leg" refer to tails as well as legs, so that the statement
"a horse has five legs" becomes true.

Language is mutable, even if horses aren't.

-- Richard
 
K

Keith Thompson

Richard Heathfield said:
Keith Thompson said:


Yeah, I noticed that too.

Unfortunately, they don't agree with me when I'm wrong, either. If they
did, life would be so much simpler.

Argh! What I meant was

People tend not to *disagree* with Richard Heathfield when he's
right.
 
S

santosh

Argh! What I meant was

People tend not to *disagree* with Richard Heathfield when he's
right.

Wonder how Richard will respond to this one now? :)

Perhaps replace the word "agree" above with "disagree"?
 
R

Richard Heathfield

Keith Thompson said:

Argh! What I meant was

People tend not to *disagree* with Richard Heathfield when he's
right.

Oh! :) Well, that's partly true, but there are plenty of counter-examples
right here in this newsgroup - people who continue to believe I'm wrong,
long after I've demonstrated otherwise.

Name names? What's the point? They know who I mean.
 
R

Richard Heathfield

Richard Tobin said:
It makes "leg" refer to tails as well as legs, so that the statement
"a horse has five legs" becomes true.

Language is mutable, even if horses aren't.

If you want to be mocked by a six-year-old, telling him or her that a horse
has five legs is a great way to start.

The statement "a horse has five legs" is false, at least for the
overwhelming majority of horses. (I know of no counter-examples.)

Calling a tail a leg does not make "leg" refer to tails as well as legs
except in the mind of the caller and those he can persuade to agree.

Language may well be mutable, but mute it too far and you risk being
misunderstood.
 
T

Tor Rustad

user923005 said:
[...]
Then those theorems are... well "UNPROVEN" theorems. PERIOD.

Actually, I agree with Jacob here. Here is a mathematical definition
of theorem, and I think it agrees with the general sense:
http://mathworld.wolfram.com/Theorem.html

I side with R.H. on this, that is to receive the status of a *theorem*,
there should exist a proof.

If the mathematical statement is believed to be true, but no proof exist
yet, a better wording is *conjecture* or *hypothesis*.

However, a proof might not be correct, and I see no point in insisting
on formal proofs over computer assisted proofs.
 
T

Tor Rustad

Richard said:
Flash Gordon said:


THANK you! At last someone sees what I'm getting at. I was beginning to
despair of my ability to explain this.

Tor's Theorem 1:

R.H. is not always correct, when he think he is.

Proof:

Double-entry bookkeeping, means there will be at least two accounts. For
sake of argument, let us pick a UK bank, with both sterling and euro
accounts.

The whole point about double-entry, is to detect errors and fraud, a
bank insider (with access to one account), who tries to credit an
account will probably be caught, when there is a mis-match between the
two "books" (assuming proper audit trails exists).

From the UK bank perspective, there is no way these calculations can
always be done *exactly* between multiple currencies. A book-entry in
e.g. sterling, of an euro account, need to be converted to euro at some
point in time, which typically involve the process of rounding
(following specific rules).

The obvious requirement our UK bank has, will be to match each account
at some cut-off times each day. This calculation should be done
*exactly*. If the currency conversion has already been done at this
point, there is no simple way to match the books *exactly*.

∎


Tor's Conjecture 1:

R.H. is not always correct, when he get the last word.

Proof:

\remark Soon to be known as "Tor's Theorem 2".

;-)
 
J

James Kuyper

Keith said:
Try harder.

Well, I'm one of the many people who was unwilling to contradict Mr.
Heathfield, and there's a very simple reason for that: I didn't think he
was wrong. Jacob might want to consider the possibility that many of the
other silent ones also agreed with Mr. Heathfield, even if Jacob finds
that very difficult to imagine.
Neither of the first two arguments to strncpy() needs to be a pointer
to a string.

There's also the fact that it usually either does not copy the entire
string, not even bothering to properly null-terminate it, or writes a
lot of stuff in addition. Only rarely, in normal usage, does it write an
exact copy of the string, and nothing else.

There are other plausible ways of defining what is meant by a "string
copy function", but requiring that it always copy the entire string,
including the terminating null character, and write nothing more than
the string, seems like a reasonable requirement to me.

The other issue debated about strncpy() is whether it was actually any
use. Well, in my programs I routinely face the following situation:

The output file spec allows a fixed amount of space for an array of
characters. The input data that is to be written into that space will
usually be small enough to fit, but cannot be guaranteed to fit. When it
does not fit, it's not an error condition - I'm supposed to put as many
characters from the beginning of the input source into the output array
as possible. Losing the terminating characters is regrettable but
permissible. The character array can be null-terminated, but is not
required to be. However, to make binary comparison of output files
easier, every character after the terminating null should also be null.

The above description applies to many of the "strings" that my programs
have to write, and also to many of the strings that they must read. It
seems to me that strncpy() is tailor-made for such use.
 
F

Flash Gordon

Tor Rustad wrote, On 06/11/07 11:38:
Tor's Theorem 1:

R.H. is not always correct, when he think he is.

Proof:

Double-entry bookkeeping, means there will be at least two accounts. For
sake of argument, let us pick a UK bank, with both sterling and euro
accounts.

The whole point about double-entry, is to detect errors and fraud, a
bank insider (with access to one account), who tries to credit an
account will probably be caught, when there is a mis-match between the
two "books" (assuming proper audit trails exists).

From the UK bank perspective, there is no way these calculations can
always be done *exactly* between multiple currencies.

Yes there is.
A book-entry in
e.g. sterling, of an euro account, need to be converted to euro at some
point in time, which typically involve the process of rounding
(following specific rules).

Each account is in a specific currency and the books for that account
are kept in the currency the account is in. A person or organisation can
have multiple accounts each in a different currency. This means that the
only way to convert money from one currency to another is to move it
from one account to another, and at that point the rounding occurs as
part of the conversion using defined rules and a specified conversion
rate, and those rules specify *exactly* what will be credited to one
account and debited from the other.
The obvious requirement our UK bank has, will be to match each account
at some cut-off times each day. This calculation should be done
*exactly*. If the currency conversion has already been done at this
point, there is no simple way to match the books *exactly*.

Incorrect, it is easy as long as you follow the requirements above.

If anyone is interested enough I could ask one of my brothers who was
doing application support & maintenance for one of the large
organisations in the City of London that works with lots of currencies.
Tor's Conjecture 1:

R.H. is not always correct, when he get the last word.

Proof:

\remark Soon to be known as "Tor's Theorem 2".

;-)

I don't think that Richard believes he is always correct.
 
R

Richard

James Kuyper said:
Well, I'm one of the many people who was unwilling to contradict
Mr. Heathfield, and there's a very simple reason for that: I didn't
think he was wrong. Jacob might want to consider the possibility that
many of the other silent ones also agreed with Mr. Heathfield, even if
Jacob finds that very difficult to imagine.

That doesn't necessarily ring true.
There's also the fact that it usually either does not copy the entire
string, not even bothering to properly null-terminate it, or writes a

"Not even bothering" what are you talking about? It is NOT supposed to.
lot of stuff in addition. Only rarely, in normal usage, does it write
an exact copy of the string, and nothing else.

Err, correct, for an exact copy we use strcpy. A different function.
There are other plausible ways of defining what is meant by a "string
copy function", but requiring that it always copy the entire string,
including the terminating null character, and write nothing more than
the string, seems like a reasonable requirement to me.

Yes it is reasonable. As is

,----
| The strncpy() function is similar, except that at most n bytes of src
| are copied. Warning: If there is no null byte among the first n
| bytes of src, the string placed in dest will not be null
| terminated.
`----

The "string placed in dest" is the clue.

You see what makes it so childishly simple is the "n" bit in the
name. it doesn't take a genius to figure out that n means
something. Possibly the number of characters to copy? Surely not!
The other issue debated about strncpy() is whether it was actually any
use. Well, in my programs I routinely face the following situation:

The output file spec allows a fixed amount of space for an array of
characters. The input data that is to be written into that space will
usually be small enough to fit, but cannot be guaranteed to fit. When
it does not fit, it's not an error condition - I'm supposed to put as
many characters from the beginning of the input source into the output
array as possible. Losing the terminating characters is regrettable
but permissible. The character array can be null-terminated, but is
not required to be. However, to make binary comparison of output files
easier, every character after the terminating null should also be
null.

The above description applies to many of the "strings" that my
programs have to write, and also to many of the strings that they must
read. It seems to me that strncpy() is tailor-made for such use.

It is nonsense to decry strncpy because some programmers can't be arsed
to read the manual properly IMO.

ps, Why is Heathfield, "Mr Heathfield" and Mr Navia is "Jacob" to you?
Are you emulating Heathfield's writing style here? Alas!
 
R

Richard Heathfield

Tor Rustad said:
Tor's Theorem 1:

R.H. is not always correct, when he think he is.

I can certainly accept that as a working hypothesis, and it agrees with a
fair amount of observational evidence, but I take issue with your proof.
Proof:

Double-entry bookkeeping, means there will be at least two accounts. For
sake of argument, let us pick a UK bank, with both sterling and euro
accounts.

Fine, but all the entries in the sterling account will be in sterling, and
all the entries in the Euro account will be in Euros. If a transaction
occurs between the two accounts, then it will be done at a particular
exchange rate that is prevalent at the date and time of the transaction,
and this exchange rate will be recorded for auditing purposes. Also, the
exchange rate will be applied according to strict rounding rules. When the
Euro was in the process of being introduced, the European Commission wrote
a whole pile of papers giving advice to companies on how to handle this
stuff in the accounts. I remember ploughing through them - not a task to
make a bunny happy, I assure you.
Tor's Conjecture 1:

R.H. is not always correct, when he get the last word.

Word games. The last word is yours if you want it - I'm done here.
 
R

Richard Heathfield

Flash Gordon said:

I don't think that Richard believes he is always correct.

Interesting philosophical point there, Flash! :)

As a matter of fact, I *do* think I'm correct, for the obvious reason that,
if I thought I were /in/correct, naturally I would modify my position.
(Doesn't everyone think that way?)

But you're right insofar as I am willing to entertain the possibility that
I could be mistaken; and if I am shown to be mistaken (as I have been, on
far more occasions than I could possibly enumerate), obviously I change my
mind, thus becoming *even more* correct than I was before! :)

Seriously, there are people here who know far more about C than I do,
people like James K, Jack K, most if not all of the Chrises, Dann, Ben
P... and these people have corrected me (correctly!) on many occasions;
also, they frequently give correct answers to questions that I'd have got
very wrong indeed if I hadn't had the good sense to keep my fingers shut.

I guess I attract flak from the trolls because I don't suffer fools gladly,
and a troll is first and foremost a fool. (A fool is not necessarily a
troll, of course, which explains the /other/ flak I get.)
 
K

Kenny McCormack

Richard said:
ps, Why is Heathfield, "Mr Heathfield" and Mr Navia is "Jacob" to you?
Are you emulating Heathfield's writing style here? Alas!

Except that he got it backwards. The hyperventilating style assumed by
Dickie H is to refer to the people you don't like as "Mr." and the ones
you do by their full names (or, occasionally, by their first names only).
This is a fairly common hack (inter alia, in the biz world); it was by
no means invented by our own Dickie H.

The punter to which rgrdev responded couldn't even get that right, and
dropped down into schoolboy/playground-speak. On the playground, you
refer to the people in power as "Mr.", and, of course, refer to the
people you're beating up on by their first names.
 
J

James Kuyper

Richard wrote:
....
ps, Why is Heathfield, "Mr Heathfield" and Mr Navia is "Jacob" to you?
Are you emulating Heathfield's writing style here? Alas!

No. I normally don't bother with "Mr." or "Mrs." for anybody, certainly
not for myself, and I routinely use first names when known, unless they
are ambiguous within the group that I'm speaking to (for example, the
multiple "Richards" who are regulars on this newsgroup). Most of the
people I deal with have no problem with that, or at least none that
they've bothered to express to me. However, I recently got reprimanded
by someone who considered it a serious insult that I didn't refer to him
as "Mr. X", whatever "X" was (I don't remember). As a reaction to that
incident, I sometimes inconsistently switch from my normal usage.
 
R

Richard

James Kuyper said:
Richard wrote:
...

No. I normally don't bother with "Mr." or "Mrs." for anybody,
certainly not for myself, and I routinely use first names when known,
unless they are ambiguous within the group that I'm speaking to (for
example, the multiple "Richards" who are regulars on this

I don't think it is necessary to litter a reply with names. It's all
self evident, generally, to whom one is referring thanks to a wonderful
invention called message threads and quoting.
newsgroup). Most of the people I deal with have no problem with that,
or at least none that they've bothered to express to me. However, I
recently got reprimanded by someone who considered it a serious insult
that I didn't refer to him as "Mr. X", whatever "X" was (I don't
remember). As a reaction to that incident, I sometimes inconsistently
switch from my normal usage.

Frankly I think calling anyone "Mr this" or "Mr that" is talking down
and appearing to rather take the high horse approach. As is evident from
the certain posts here.

Still, all to their own.
 
J

jameskuyper

Richard wrote:
....
I don't think it is necessary to litter a reply with names. It's all
self evident, generally, to whom one is referring thanks to a wonderful
invention called message threads and quoting.

The original draft of the message in question was filled with "he" and
"him" and "his". I only replaced them with actual names when I
realized that it was often unclear who I was referring to.
 
B

Ben Bacarisse

Keith Willis said:
I'll see your dictionary and raise you one:

http://www.askoxford.com/concise_oed/theorem?view=uk

"a general proposition not self-evident but proved by a chain of
reasoning"

....and I'll raise you to the full OED:

"a. In Mathematics and Physics; spec. in Geometry, a proposition
embodying merely something to be proved..."[1]

Presumably the argument here is whether the "loose" sense of something
asserted and not yet proved (or disproved) is in the dictionary. Of
course, the OED gives the usual, stricter, meaning above this one.

For what it is worth, I am with RH on this (despite the detail from
the dictionary) because I don't think the Church-Turing thesis can be
formulated as a theorem (or, better, a conjecture) because it is by
its nature vague about the formality.

[1] The "merely" here refers to the stronger notion of a "problem" in
geometry -- something to be done (like squaring the circle) rather
than "merely" proved or disproved.
 

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

Fibonacci 0
Adding adressing of IPv6 to program 1
C language. work with text 3
code review 26
Can't solve problems! please Help 0
compressing charatcers 35
Strange bug 65
K&R exercise 5-5 10

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top