The function recognizes a string containing the following:
optional white space
an optional plus or minus sign
a sequence of digits containing an optional decimal point
an optional e or E, followed by an optionally signed sequence of digits.
…
If the correct value would cause overflow, plus or minus HUGE_VAL is returned according to the
sign, and errno is set to ERANGE. If the correct value would cause underflow, then zero is
returned, and errno is set to ERANGE.
This function returns zero when the input string can’t be converted
…
So, if you want ERANGE you have to pass string like “9.999e9999” or something big enough for duble.
But I think it should gives
infinit,err=0,errno=No error.
Try
double err;
Sorry, the double part I was just using in my short example, sorry bout
that
The issue is that i’m using it to strip of numbers before some notion.
ie ‘inch’ but since something is phucked, and QNX strtod seems to think
‘infinit’ is a number, it gives p = “ch”
Which, won’t match a strcmp(“inch”…)
And since it do think infinit is a number, then it really should set
ERANGE, since well, infinit is kind of… out of range eh?
Or , as i think it’s supposed to, simply ignore infinit and give me my
inch back :}
I’m having some problems with strtod, and stuff containing the string
‘infinit’
According to the latest C standard, strtod() is supposed to recognize
“inf” and “infinity”. strtod(“infinit”,&p) should return infinity and
leave p pointing at “init”.
There was a thread in comp.os.c in March discussing this – a Google
search for “strtod INFINIT” finds it. (In particular, take a look at
P.J.Plaguer’s responses: QNX uses his C library.)
The function recognizes a string containing the following:
optional white space
an optional plus or minus sign
a sequence of digits containing an optional decimal point
an optional e or E, followed by an optionally signed sequence of digits.
…
If the correct value would cause overflow, plus or minus HUGE_VAL is returned according to the
sign, and errno is set to ERANGE. If the correct value would cause underflow, then zero is
returned, and errno is set to ERANGE.
This function returns zero when the input string can’t be converted
…
So, if you want ERANGE you have to pass string like “9.999e9999” or something big enough for duble.
But I think it should gives
infinit,err=0,errno=No error.
Try
double err;
Eduard.
ed1k at ukr dot net
Then changing the “infinit” string to
“inch” ,
ch,0,errno=No Error.
I’m not sure what the standard say, but system like Linux doesn’t seem
to care about ‘infinit’, and returns “inch” when the input string is “inch”.
I’m having some problems with strtod, and stuff containing the string
‘infinit’
According to the latest C standard, strtod() is supposed to recognize
“inf” and “infinity”. strtod(“infinit”,&p) should return infinity and
leave p pointing at “init”.
There was a thread in comp.os.c in March discussing this – a Google
search for “strtod INFINIT” finds it. (In particular, take a look at
P.J.Plaguer’s responses: QNX uses his C library.)
The issue is that i’m using it to strip of numbers before some notion.
ie ‘inch’ but since something is phucked, and QNX strtod seems to think
‘infinit’ is a number, it gives p = “ch”
The standard actually says that the string can contain (case instensive)
INF, INFINITY, NAN or NAN(n-char-sequence).
And since it do think infinit is a number, then it really should set
ERANGE, since well, infinit is kind of… out of range eh? >
ERANGE is used if the result isn’t representable from the ranges HUGE_VAL
and HUGE_VAL[FL].
Or , as i think it’s supposed to, simply ignore infinit and give me my
inch back :}
Why not use strtok() to search for your notation, or use sscanf() to do the
conversion if you can be sure of the format of the string.
With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>
Wojtek Lerch <wojtek_l@yahoo.ca> wrote:
: According to the latest C standard, strtod() is supposed to recognize
: “inf” and “infinity”. strtod(“infinit”,&p) should return infinity and
: leave p pointing at “init”.
: There was a thread in comp.os.c in March discussing this – a Google
: search for “strtod INFINIT” finds it. (In particular, take a look at
: P.J.Plaguer’s responses: QNX uses his C library.)
Before anyone else can say it, no, it isn’t documented. I’ll add it to the
queue.
Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems