Deutsch   English   Français   Italiano  
<v85dpo$falk$1@solani.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.misty.com!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: Mild Shock <janburse@fastmail.fm>
Newsgroups: comp.lang.prolog
Subject: New milestone float formatting [LoL] (Was: Request for comments,
 Novacore the sequel to ISO modules)
Date: Sun, 28 Jul 2024 14:32:58 +0200
Message-ID: <v85dpo$falk$1@solani.org>
References: <db8a6771-3e54-485b-b391-310658dd6f52n@googlegroups.com>
 <d9588b9c-edcc-4f8b-85d2-7487b5556798n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 28 Jul 2024 12:32:56 -0000 (UTC)
Injection-Info: solani.org;
	logging-data="502452"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
 Firefox/91.0 SeaMonkey/2.53.18.2
Cancel-Lock: sha1:plKoyOCEaqWn5LZhCTXEthW4D5o=
In-Reply-To: <d9588b9c-edcc-4f8b-85d2-7487b5556798n@googlegroups.com>
X-User-ID: eJwFwQkBwDAIA0BLoRSyyuH1L2F3pi5evG5+bW0jIsGPnLfv+CYKNcpxPp1oZUqjG6IZdVUX3+QxsEdOzg9vTBY+
Bytes: 3640
Lines: 88

Hi,

To capture some critical examples of float to string
conversion I went with this kind of little excess
precision and had this float to string conversion:

          return shape_number(num.toPrecision(17));

Which gives this unfortunate result, still in release
1.2.1 of Dogelog Player for JavaScript seen:

?- between(1,10,N), X is (20+N)/10, write(X), nl, fail; true.
2.1000000000000001
2.2000000000000002
2.2999999999999998
2.3999999999999999
2.5
2.6000000000000001
2.7000000000000002
2.7999999999999998
2.8999999999999999
3.0

One work around is to check whether precision 16 would
also work. Like this code here:

         let res = num.toPrecision(16);
         if (Number(res) === num) {
             return shape_number(res);
         } else {
             return shape_number(num.toPrecision(17));
         }

The results are much more eye friendly:

?- between(1,10,N), X is (20+N)/10, write(X), nl, fail; true.
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
3.0
true.

Can we accept this solution? Will it slow down printing?

Mild Shock schrieb:
> The new multilingual strings are also an exercise in
> Novacore. There were a few issues that needed novel
> Prolog solutions, to make a Novacore solution.
> 
> One problem was I didn't want to use library(format)
> and format/3 to format multilingual strings when
> generating error messages. This addresses more
> 
> the later multilingual strings processing than the
> multilingual strings store itself. So how resolve this
> paradox? Here is my take, a mini format/3 boostraped
> 
> from the Dogelog Player specific atom_split/3:
> 
> % sys_inter_polate(+Stream, +Atom, +List)
> sys_inter_polate(Stream, Template, Args) :-
>     atom_split(Template, '~', [Head|Tail]),
>     put_atom(Stream, Head),
>     sys_zipper_output(Args, Tail, Stream).
> 
> % sys_zipper_output(+List, +List, +Stream)
> sys_zipper_output([Arg|Args], [Head|Tail], Stream) :-
>     writeq(Stream, Arg),
>     put_atom(Stream, Head),
>     sys_zipper_output(Args, Tail, Stream).
> sys_zipper_output([], [], _).
> 
> It only understands format specifier '~', but is sufficient:
> 
> /* German Text */
> strings('syntax_error.singleton_var', de, 'Alleinstehende Variable(n) ~, anonyme Variable(n) (_) benutzen.').
> 
> /* English and Fallback Text */
> strings('syntax_error.singleton_var', '', 'Singleton variable(s) ~, use anonymous variable(s) (_).').
> 
> LoL
>