[sac-user] print function alternatives?

Clemens Grelck c.grelck at uva.nl
Mon Aug 2 23:47:05 CEST 2010


Much better. ;-)

What might prove problematic in ArrayFormat is that, if I understand
it correctly, an entire array is transformed into a string before that
string (normally) is printed to some file descriptor and then removed
again.

I think this would be a good example for having higher-order functions,
because what you in the end want to do is to map a print function to each
element of an array. And to have this print function user-controlled.

A less comprehensive but then much easier and quicker to realise solution
could be to simply expose the format string in the user API. The
implementation of the ArrayIO module already has this abstraction layer.
At the moment, the exposed API function calls this one hard-wiring the
format string. I think this could be realised within 15 minutes or so.

  Clemens


Robert Bernecky wrote:
> Is this better?
> 
> 0.07
> 0.07
> 0.0700000000000000067
> 
> rbe at obelix:~> cat crud.sac
> 
> use Array:all;
> use StdIO:all;
> use ArrayFormat:all;
> 
> int main()
> {
>  x = 0.07;
>  show(x);
>  show(format(x));
>  show(format(x,18));
>  return(0);
> }
> 
> Bob
> 
> Raphael 'kena' Poss wrote:
>> Hi all,
>>
>> Op 2 aug 2010, om 18:45 heeft Robert Bernecky het volgende geschreven:
>>> In particular, it still uses printf() [...]
>>> My intent was to make it use a precise formatter, such
>>> as that proposed in "Printing Floating-Point Numbers Quickly and 
>>> Accurately", by Robert G. Burger and R. Kent Dybvig.
>>
>> For your information, many open-source Unices nowadays use the gdtoa 
>> library by D. Gay from netlib: http://www.netlib.org/fp/gdtoa.tgz
>>
>> This uses concepts and algorithms from
>>
>> T. J. Dekker, "A Floating-Point Technique for Extending the
>> Available Precision", Numer. Math. 18 (1971), pp. 224-242
>>
>> and
>>
>> "How to Print Floating-Point Numbers Accurately" by
>> Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].
>>
>> As far as precision goes, this is formally specified. I don't know how 
>> it compares to the techniques in Burger & Dybvig, actually.
>>
>>
>> As an option, is it possible to output floats in hexadecimal? This 
>> should prevent rounding errors.
>>
> _______________________________________________
> sac-user mailing list
> sac-user at sac-home.org
> http://lists.sac-home.org/mailman/listinfo.cgi/sac-user

-- 
----------------------------------------------------------------------
Dr Clemens Grelck                                     Science Park 107
Universitair Docent                                  1098 XG Amsterdam
                                                              Nederland
Universiteit van Amsterdam
Instituut voor Informatica                       T +31 (0) 20 525 7578
                                                  F +31 (0) 20 525 7419
Office F2.46                                www.science.uva.nl/~grelck
----------------------------------------------------------------------



More information about the sac-user mailing list