[mercury-users] [Feature request] Printing reasonable floats/printer pred

Ralph Becket rafe at csse.unimelb.edu.au
Mon Feb 12 13:04:49 AEDT 2007


Julien Fischer, Monday, 12 February 2007:
> 
> On Sun, 11 Feb 2007 doug.auclair at logicaltypes.com wrote:
> 
> >Dear all, I wrote and Julian responded:
> >
> >>>Is it possible to set some value in the io state to control how
> >>>float is printed?
> >>Nobody has responded, so: AFAICT, no.  My quick research showed
> >>that: [snip]
> >
> >Therefore I have a feature request, which is that the precision of
> >floats be part of io.state accessable to the user, so that write/[3,4]
> >prints a float based on this value.
> 
> write/{3,4} are based on stream.string_writer.write which doesn't
> (necessarily) have access to the I/O state.
> 
> I think a better solution would be to pass an additional argument
> to write that specifies things like how floats should be formatted.
> (The default settings for this argument would correspond to the
> existing behaviour for write/{3,4}).

I think the solution that would satisfy 99% of users would be to simply 
trim redundant trailing zeroes from floats unless a specific precision
has been specified.  MR_sprintf_float currently uses 

	sprintf(buf, "%#.*g", i, f);

and the `#' modifier has the unfortunate effect of suppressing `%g''s
usual redundant zero removal behaviour.

I'm trying to coax the compiler into testing a fix for this, but am
being thwarted by the build system...
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list