> > I can't find such functions, but it is the only option left.  Therefore,
> > such a function has to be written, may as well be called qsprintf() or
> > something.  It doesn't need to be complicated, only handle "%d", "%s"
> > and "%f", maybe with a few standard flags.  There is a number of such
> > functions in GNU Go, by the way.
> 
> All I have found in GnuGO were wrappers for standard library functions.
> Were you accidentally referring to those, or did I miss something?

I meant those, just didn't check how exactly they were written.

> Anyway, I have rewritten utils_format_double() to a "direct" version
> that only uses some math-library routines (most importantly log10), but
> does the formatting itself.

I'd use a few constants instead, since the number of digits after point
is limited to 6 anyway.  But the main thing for it is to work ;), so do
it as you see fit.

> Next problem now that the komi is stored 
> correctly, reading it back truncates the decimals. Without actually
> verifying, I'm pretty sure that's because atof() expects a ',', but
> finds a '.'. So if you don't object, I'll write another function
> utils_parse_double() to be the inverse of utils_format_double().

Fine.

> I'm not sure whether we need our own formatting for %d (or even %s), so
> for the time being, it's probably easiest to just use
> sprintf(str, "...%s...", ..., utils_format_double(f), ...);
> instead of
> sprintf(str, "...%f...", ..., f, ...);

One important consideration is that utils_format_double() works with a
static buffer.  It's very inconvenient when you need to write several
numbers in one string because you need to copy, free allocated memory
etc.  I think I'll write such a function when I finally get to working
with Quarry again.

> I also
> want to specify utils_format_double() a little more rigorously. Up to
> now, it used as many decimals as sprintf spits out, truncating zeros. My
> preliminary version always uses exactly one decimal. Probably it's
> better to use up to n decimals if needed, where n is either a constant
> (5?) or an additional parameter. 
> E.g. 1         -> 1.0
>      1.5       -> 1.5
>      1.12345   -> 1.12345
>      1.1234567 -> 1.12346
> Thoughts?

sprintf() formats with six digits after point by default.  I think 6 is
a good limit, so what you described above is fine except that 1.1234567
should be formatted as "1.123457".

> > Please provide ChangeLog entries
> > along with patches (if you use Emacs, `C-x 4 a' does everything but
> > writing the actual text for you).
> 
> I'm using vim - that's the masochist in me :) 

Well, this means more work for you, sorry.

Paul

Reply via email to