Question for a REAL expert on casting double to float...

N

Nick Keighley

Don't you have a C library manual?  It is all documented.  Most
systems also have extensions (and some have limitations) so you can't
avoid reading your library's documentation.

actually with one compiler when we asked for the documentaion they
sent a copy of the C standard. Which was nice (I've still got it)
but not what we asked for! And their library wasn't quite complete...
 
N

Nick Keighley

Hey, "rubbish" would be a treat compared to what often happens
with *scanf()!!!  Why do you think I "rolled my own"?  (I actually
have some very specific requirements that can't be handled properly by
*scanf() at all.)
[...]
Are you sure *scanf() can't handle your requirements?  You didn't know
about "%hd"; perhaps there are other features you don't know about
that would solve your problem.
I sure hope not, but I'll take you up on this.  The most important
thing I need for a certain amount of my file parsing is that the
*scan*() function ALWAYS increments to the next argument whether
or not the last field was actually successfully scanned.
I'm not quite sure what that means.  If an argument isn't successfully
scanned, how do you even define how much text to skip to get to the
next argument?

Man, have you got a standard library "mindset"...can't comprehend
anything later than 1975 and punch-cards...

a strange way to ask for help. So you've got some poorly
structured input. Is a human being typeing it in?


Of course, I explain it below, but you still don't seem to be able
to "get it"...

perhaps you're bad at explaining?

"don't scan%d2nd don't scan%ddon't scan%fdon't scan%s"

some sample input would help... (yes I know there's
some later).
See the three fields to be scanned?  Here, here's some precious
"whitespace" to help:

"don't scan %d 2nd don't scan %d don't scan %f don't scan %s"

no use to me
Are you missing the fact that I already did this years ago?

are you missing the fact that we can't read minds?
What is actually wrong with this approach?

 Did the
fact that I posted the code for it throw you off?  The scannable fields
are not delimited by anything other than the preceding (if any) and
following text, which I then use to extract a pointer to the
beginning of the scannable field and the length the field.  Numeric
fields are copied to a buffer for strto*() function conversion and
assigned to their pointer arguments; string fields are
directly copied to their pointer arguments.



Maybe I already did that too, though this is more like "regular
expression"-lite...hell, a full "regex" package came with my
compiler...stuff
like that is literally "a dime a dozen"...

so is it a regexp or not?


Actually, it's not that odd, if you could change your "mindset".
I think the way *scanf() works is pretty odd; it's kind of like fishing
while blind in a sewer, mostly you just catch CHUDs...

I'm of the "the input is either correctly formatted or not" school.
"correctly formatted" can cover a lot of ground, but I still
like to know where the edge of acceptance is. If the input is really
loosely structured I'd consider a simple parser.

I don't use this to "fish" for anything; I know exactly what I want,
mostly because I wrote it there.

except sometimes you didn't...

 Sometimes I don't want anything, so
that's what I write...and that's what I want when I read it back...

probably not on its own. I tend to only use it on well
structured input.


they are very well documented. And if you have the right mind set
not at all quirky :)

Remember our format string:

"don't scan %d 2nd don't scan %d don't scan %f don't scan %s"

OK, here are some strings and how they SHOULD scan:

"don't scan 123 2nd don't scan 345 don't scan 1.23 don't scan scan"
field 1 = 123, field 2 = 345, field 3 = 1.23, field 4 = "scan"

"don't scan 2nd don't scan don't scan 1.23 don't scan "
field 1 = who cares, field 2 = who cares, field 3 = 1.23, field 4 = ""

"don't scan 2nd don't scan don't scan don't scan scan"
field 1 = who cares, field 2 = who cares, field 3 = who cares, field 4 =
"scan"

This is what I want, and what I GET, with my version of *scanf(), but
the idiotic *scanf() functions would probably put 2 into field 1
for the second two, and 1 into field 2 for the third, which isn't so
bad because I didn't care about those fields in the first place,
but write garbage into field 3 for the second, if not just crashing
completely, and definitely bomb out on field 4 for the second
two, because they would have been scanning in vain for
some digits for strtol() or strtod() to convert for field 2 or 3...as I
explained very simply, they don't advance automatically to the
next argument if a field fails to scan, instead they just look for
something to scan into the current argument, quite often with
program-ending results...

scanf() is designed for well structured input

How about using scanf() to do the actual field parsing?


--
Nick Keighley

A lot of the c.l.c. verbiage seems to be devoted to the numerical
density of cavorting nubile seraphim upon pinheads.
CBFalconer
 
B

Bill Reid

...something that can't be automatically quoted on my newsreader since
you used the wrong "Reply" link on Google(TM) Groups, despite being told
DOZENS of times by a newsgroup regular EXACTLY how to do it...

So I'll just sum up without your unquotable text; if you really want a
specific response to each of your non-sequiturs, you might be able to
reply to your own message using the CORRECT "Reply" link, and
then I could address each non-sequitur individually...

Mr. Thompson offered what in a courtroom might be called a
"proffer", an offer of evidence to prove a fact, if I were to provide
him with a statement of my requirements. I made just such a
statement, and he reneged on his "proffer", preferring to claim
that he "didn't understand" the clearly-stated requirements.

Outside of the very specific question that I posed to initiate
this thread, I have no need of ANY "help" in writing or re-writing
the function, since I wrote it years ago and have used it probably
like a million times since then in production code. It meets all the
elements of the clearly-stated requirements, and I not once, but
TWICE posted part of the code that showed how the function was
written. Several people here need to be able to not only read
code for comprehension, but also the English language...

As part (and probably genesis) of these information communication
problems, you need to be able to make clear-cut practical logical
distinctions. You consistently conflated input that DELIBERATELY
was missing certain fields with "poorly-structured input", no
matter how many times it was explained to you, and how many
examples you were shown. You also conflate *scanf() as
"requiring structured input" when no such thing is actually
true; the way *scanf() is written it will "accept" very badly-structured
input and "silently" give you bad values for your arguments while
apparently succeeding, or not scan PERFECTLY structured
input with PERFECTLY valid scannable fields.

This is because like so much bad code, *scanf() was written
according to requirements based first and foremost on the sloth
of the programmer who wrote it, the very self-same type of
programmer that would look at a clearly-stated set of requirements
and exclaim "I DON'T GET IT?!??!! GIVE ME AN EXAMPLE...I
DON'T GET THE EXAMPLE EITHER!!!!!!! YOU JUST KEEP
EXPLAINING IT TO ME, I'LL BE OVER HERE DRINKING A
BEER!!!"

There is NO way I can use *scanf() in any rational fashion
to acheive the requirements I stated. About the only way to
do so would be to ridiculously and wastefully call *scanf()
to convert and assign a single field after I had done all the
"heavy lifting" of writing the whole argument field-scanning
variadic loop, but *scanf() essentially just calls strto*()
functions at that point, SO WHY DON'T I JUST CALL
THEM MYSELF AND ELIMINATE THE POINTLESS
MIDDLEMAN?!??!! As far as using "using *scanf() to
parse the field", GET SERIOUS, I hope nobody is so
deranged to conflate *scanf() with any type of tokenizer
or regular expression parser; it is an artless ram-shackle
piece of junk that relies almost totally on it's conversion
functions to define a "scannable" field, and can only be
TRULY safely used to scan an input string that you KNOW
to be perfectly formatted in every way (it CANNOT be SAFELY
used to determine the actual FORMAT of the string, since
it only scans as best as it can (badly), it doesn't PARSE).
 
N

Nick Keighley

..something that can't be automatically quoted on my newsreader

other people manage. perhaps your news reader is broken.
since
you used the wrong "Reply" link on Google(TM) Groups, despite being told
DOZENS of times by a newsgroup regular EXACTLY how to do it...

I've missed these posts. I rememeber being told once (perhaps by you)
but when I asked for more information I didn't get any. Perhaps if
you explained my error I could mend my ways.

I'll snip most of your contentless ranting.

Outside of the very specific question that I posed to initiate
this thread, I have no need of ANY "help" in writing or re-writing
the function, since I wrote it years ago and have used it probably
like a million times since then in production code.

strange I thought you asked a question at the beginning.
In fact if your code was perfected years ago why are you asking
questions about float and double?

As part (and probably genesis) of these information communication
problems, you need to be able to make clear-cut practical logical
distinctions.  You consistently conflated input that DELIBERATELY
was missing certain fields with "poorly-structured input",

perhaps I used a poor term. Would you prefer "weakly" structured.
erm "not rigidly structured"? Flexible structured?
no
matter how many times it was explained to you, and how many
examples you were shown.

I only saw one post that had examples.
 You also conflate *scanf() as
"requiring structured input" when no such thing is actually
true; the way *scanf() is written it will "accept" very badly-structured
input and "silently" give you bad values for your arguments while
apparently succeeding, or not scan PERFECTLY structured
input with PERFECTLY valid scannable fields.

I disagree. If scanf() is properly used it will read the
fields you specify. I agree it doesn't do what you want
but that isn't scanf()s "fault". Note all caps is like
shouting. It makes it look like you're cross or something.

This is because like so much bad code, *scanf() was written
according to requirements based first and foremost on the sloth
of the programmer who wrote it,

I disagree. scanf() can be a bit arcane. But it does a useful
job. perhaps if you'd read scanf()s documentation you would't
be reinventing wheels and trying to stuff floats into doubles.

the very self-same type of
programmer that would look at a clearly-stated set of requirements
and exclaim

obviously your idea of a clear requirment differs from mine.
If it's an input stream I like BNF or solid examples. Your
vague scanf()-like format specs didn't cut the mustard.
There are two ways a requirement can fail to be communicated.
The receiver is stupid or the message is ambiguous or
poorly structured.

There is NO way I can use *scanf() in any rational fashion
to acheive the requirements I stated.

ok. I just wondered if you could smash the input string
up into tokens then use scanf() on the tokens. Just a
thought.

 About the only way to
do so would be to ridiculously and wastefully call *scanf()
to convert and assign a single field after I had done all the
"heavy lifting" of writing the whole argument field-scanning
variadic loop, but *scanf() essentially just calls strto*()
functions at that point, SO WHY DON'T I JUST CALL
THEM MYSELF AND ELIMINATE THE POINTLESS
MIDDLEMAN?!??!!

ok... so you aren't too keen on that idea...


 As far as using "using *scanf() to
parse the field", GET SERIOUS, I hope nobody is so
deranged to conflate *scanf() with any type of tokenizer
or regular expression parser; it is an artless ram-shackle
piece of junk that relies almost totally on it's conversion
functions to define a "scannable" field, and can only be
TRULY safely used to scan an input string that you KNOW
to be perfectly formatted in every way

ooo! isn't that strongly structured input?
(it CANNOT be SAFELY
used to determine the actual FORMAT of the string, since
it only scans as best as it can (badly), it doesn't PARSE).

normally I'd plonk you at this point but you make me smile!

:)


--
Nick Keighley

If cosmology reveals anything about God, it is that He has
an inordinate fondness for empty space and non-baryonic dark
matter.
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top