Floating point conversion RFC
chris hermansen
clhermansen@gmail.com
Fri Jun 5 19:31:38 GMT 2026
Ok some details below:
On Fri, Jun 5, 2026 at 11:55 AM chris hermansen <clhermansen@gmail.com>
wrote:
> Thank you!
>
> On Thu, Jun 4, 2026, 18:01 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
> wrote:
>
>>
>> Hi Chris.
>>
>> On Thu, Jun 04, 2026 at 09:06:30AM -0700, chris hermansen wrote:
>> > Good morning everyone,
>> >
>> > Today a search led me to this paper which I find quite interesting and
>> > perhaps something to consider in the context of deciding whether we need
>> > a replacement for the routines in the Revised Report or van Vliet.
>> >
>> > https://arxiv.org/pdf/2603.06581
>> >
>> > Thoughts and comments please!
>> >
>>
>>
>> These are cool stuff! Thanks for sharing.
>>
>> Although for the implementation, my suggestion is to use available C
>> functions (either directly calling libc functions or by copying the
>> implementation from Gnulib/glibc). This has the benefit of getting
>> things rolling faster and to have more confidence in the result.
>>
>> I'm not familar with transput much, so I cannot give concrete proposals;
>> but I'd suggest for the conversion from string to real/long real/loong
>> real,
>> one can just use strtof/strtod/strtold C functions, and for conversion
>> from
>> real/long real/loong real to string, just use printf! (For sure these
>> should be wrapped in a shim C layer to become ga68-friendly).
>>
>> If you give me declarations of the desired Algol 68 procedures, I can
>> send a patch.
>>
>
> Most kind of you, thanks for the offer!
>
> I will refresh my memory on their particulars and get back to you.
>
>>
>>
>> Thanks for the work, and happy Algoling!
>>
>
> That's the thing!
>
There are three "conversion routines" "whole, fixed and float [that]
are intended to be used with the formatless output routines put, print and
write when it is required to have a little extra control over the layout
produced" (Revised Report §10.3.2.1 pp 158-163).
Jose has already transcribed the RR versions and they are available in the
more recent releases.
van Vliet provides code for some of these, and in other cases just
comments. Given that there is the need to:
1. write some more code anyway;
2. conform to IEEE 754;
I would like to move to Dragonbox or Schubfach eventually. But as you say
going with wrappers for C functions doesn't seem too off the wall as a stop
gap.
So, the three routines, with comments from the RR, are:
proc whole= (number v, int width) string: {
print (whole (i, -4))
which might print ",.,.,.O", ",.,.99", ",.-99", "9999" or, if i were
greater than 9999, "****", where "*" is the yield of errorchar;
print (whole (i, 4))
which would print ",. +99" rather than ",.,.99";
print (whole (i, 0))
which might print "O", "99", "-99", "9999" or "99999"; }
proc fixed= (number v, int width, after) string: {
print (fixed (x, -6, 3))
which might print ",.2.718", "27.183" or "271.83" (in which one
place after the decimal point has been sacrificed in order to fit
the number in);
print (fixed (x, 0, 3))
which might print "2.718", "27.183" or "271.828"; }
proc float= (number v, int width, after, exp) string: {
print (float (x, 9, 3, 2))
which might print "-2.718₁₀+0", "+2.718₁₀-1", or "+2.72₁₀+11" (in
which one place after the decimal point has been sacrificed in
order to make room for the unexpectedly large exponent). }
I believe we have previously discussed, and agreed that, "e" should be used
rather than subscript "10".
If you return numeric strings "in the ballpark", I can add the leading +,
assure the number of digits etc in the wrappers.
Thanks again for the offer!
--
Chris Hermansen · clhermansen "at" gmail "dot" com
C'est ma façon de parler.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/algol68/attachments/20260605/ed4ae7e8/attachment.htm>
More information about the Algol68
mailing list