Thread overview
How do you write reals or floats? (I have one sol here)
Jun 02, 2004
hellcatv
Jun 04, 2004
Walter
Jun 04, 2004
hellcatv
Jun 04, 2004
Walter
June 02, 2004
I was desparately browsing through the phobos lib... and I haven't found a way
to copy a real to a string
I tried snprintf but it would often leave garbage in the string (I'm not sure
why yet...but it wouldn't work with gdc)
so I wrote my own ftoa
http://svn.dsource.org/svn/projects/deliria/turing/

also I have the problem that since it's called ftoa import won't bring it in
because when I call
ftoa() it says "cannot call module" instead of calling the function



June 04, 2004
This should work:

    char[100] buffer;
    snprintf(buffer, buffer.length, "%Lg", r);

<hellcatv@hotmail.com> wrote in message news:c9llt3$bs3$1@digitaldaemon.com...
> I was desparately browsing through the phobos lib... and I haven't found a
way
> to copy a real to a string
> I tried snprintf but it would often leave garbage in the string (I'm not
sure
> why yet...but it wouldn't work with gdc)
> so I wrote my own ftoa
> http://svn.dsource.org/svn/projects/deliria/turing/
>
> also I have the problem that since it's called ftoa import won't bring it
in
> because when I call
> ftoa() it says "cannot call module" instead of calling the function
>
>
>


June 04, 2004
that's nice but snprintf isn't even provided in dmd0.91 (at least it claims it
doesn't exist)
only sprintf
and the buffer overrun stuff that it could (and probably will not) cause is just
unfriendly.

why is there an atof and no ftoa? :-)
or at least a std.string function. either is bound to be faster than having
snprintf parse a format string then assign to a preallocated array of
undetermined length, and return that to the host program which then has to read
the whole string, determine the ending length and truncate it at that point for
the rest of the D program to use :-)


In article <c9p94o$2kb6$1@digitaldaemon.com>, Walter says...
>
>This should work:
>
>    char[100] buffer;
>    snprintf(buffer, buffer.length, "%Lg", r);
>
><hellcatv@hotmail.com> wrote in message news:c9llt3$bs3$1@digitaldaemon.com...
>> I was desparately browsing through the phobos lib... and I haven't found a
>way
>> to copy a real to a string
>> I tried snprintf but it would often leave garbage in the string (I'm not
>sure
>> why yet...but it wouldn't work with gdc)
>> so I wrote my own ftoa
>> http://svn.dsource.org/svn/projects/deliria/turing/
>>
>> also I have the problem that since it's called ftoa import won't bring it
>in
>> because when I call
>> ftoa() it says "cannot call module" instead of calling the function
>>
>>
>>
>
>


June 04, 2004
<hellcatv@hotmail.com> wrote in message news:c9pclq$2pn6$1@digitaldaemon.com...
> that's nice but snprintf isn't even provided in dmd0.91 (at least it
claims it
> doesn't exist)
> only sprintf

There's std.c.stdio._snprintf().

> and the buffer overrun stuff that it could (and probably will not) cause
is just
> unfriendly.

I know.

> why is there an atof and no ftoa? :-)
> or at least a std.string function. either is bound to be faster than
having
> snprintf parse a format string then assign to a preallocated array of undetermined length, and return that to the host program which then has to
read
> the whole string, determine the ending length and truncate it at that
point for
> the rest of the D program to use :-)

You're right. It just hasn't been done yet.